Skip to content

Commit d763365

Browse files
committed
Rebased around the new egui_for_winit
# Conflicts: # Cargo.lock # egui_glium/src/lib.rs
1 parent f2dd3df commit d763365

File tree

15 files changed

+706
-545
lines changed

15 files changed

+706
-545
lines changed

Cargo.lock

Lines changed: 23 additions & 65 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

egui_glium/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ all-features = true
2525
egui = { version = "0.14.0", path = "../egui", default-features = false, features = ["single_threaded"] }
2626
egui-winit = { version = "0.14.0", path = "../egui-winit", default-features = false }
2727
epi = { version = "0.14.0", path = "../epi" }
28-
glium = "0.30"
28+
glutin = "0.27"
29+
glow = "0.11"
2930

3031
# feature "persistence":
3132
directories-next = { version = "2", optional = true }

egui_glium/examples/pure.rs

Lines changed: 52 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
//! Example how to use pure `egui_glium` without [`epi`].
2-
use glium::glutin;
3-
4-
fn create_display(event_loop: &glutin::event_loop::EventLoop<()>) -> glium::Display {
2+
fn create_display(
3+
event_loop: &glutin::event_loop::EventLoop<()>,
4+
) -> (
5+
glutin::WindowedContext<glutin::PossiblyCurrent>,
6+
glow::Context,
7+
) {
58
let window_builder = glutin::window::WindowBuilder::new()
69
.with_resizable(true)
710
.with_inner_size(glutin::dpi::LogicalSize {
@@ -10,24 +13,37 @@ fn create_display(event_loop: &glutin::event_loop::EventLoop<()>) -> glium::Disp
1013
})
1114
.with_title("egui_glium example");
1215

13-
let context_builder = glutin::ContextBuilder::new()
14-
.with_depth_buffer(0)
15-
.with_srgb(true)
16-
.with_stencil_buffer(0)
17-
.with_vsync(true);
18-
19-
glium::Display::new(window_builder, context_builder, event_loop).unwrap()
16+
let gl_window = unsafe {
17+
glutin::ContextBuilder::new()
18+
.with_depth_buffer(0)
19+
.with_srgb(true)
20+
.with_stencil_buffer(0)
21+
.with_vsync(true)
22+
.build_windowed(window_builder, event_loop)
23+
.unwrap()
24+
.make_current()
25+
.unwrap()
26+
};
27+
28+
let gl = unsafe { glow::Context::from_loader_function(|s| gl_window.get_proc_address(s)) };
29+
30+
unsafe {
31+
use glow::HasContext;
32+
gl.enable(glow::FRAMEBUFFER_SRGB);
33+
}
34+
35+
(gl_window, gl)
2036
}
2137

2238
fn main() {
2339
let event_loop = glutin::event_loop::EventLoop::with_user_event();
24-
let display = create_display(&event_loop);
40+
let (gl_window, gl) = create_display(&event_loop);
2541

26-
let mut egui = egui_glium::EguiGlium::new(&display);
42+
let mut egui = egui_glium::EguiGlium::new(&gl_window, &gl);
2743

2844
event_loop.run(move |event, _, control_flow| {
2945
let mut redraw = || {
30-
egui.begin_frame(&display);
46+
egui.begin_frame(gl_window.window());
3147

3248
let mut quit = false;
3349

@@ -49,36 +65,31 @@ fn main() {
4965
});
5066
});
5167

52-
let (needs_repaint, shapes) = egui.end_frame(&display);
68+
let (needs_repaint, shapes) = egui.end_frame(gl_window.window());
5369

5470
*control_flow = if quit {
5571
glutin::event_loop::ControlFlow::Exit
5672
} else if needs_repaint {
57-
display.gl_window().window().request_redraw();
73+
gl_window.window().request_redraw();
5874
glutin::event_loop::ControlFlow::Poll
5975
} else {
6076
glutin::event_loop::ControlFlow::Wait
6177
};
6278

6379
{
64-
use glium::Surface as _;
65-
let mut target = display.draw();
66-
6780
let clear_color = egui::Rgba::from_rgb(0.1, 0.3, 0.2);
68-
target.clear_color(
69-
clear_color[0],
70-
clear_color[1],
71-
clear_color[2],
72-
clear_color[3],
73-
);
74-
75-
// draw things behind egui here
76-
77-
egui.paint(&display, &mut target, shapes);
78-
79-
// draw things on top of egui here
80-
81-
target.finish().unwrap();
81+
unsafe {
82+
use glow::HasContext;
83+
gl.clear_color(
84+
clear_color[0],
85+
clear_color[1],
86+
clear_color[2],
87+
clear_color[3],
88+
);
89+
gl.clear(glow::COLOR_BUFFER_BIT);
90+
}
91+
egui.paint(&gl_window, &gl, shapes);
92+
gl_window.swap_buffers().unwrap();
8293
}
8394
};
8495

@@ -91,12 +102,19 @@ fn main() {
91102

92103
glutin::event::Event::WindowEvent { event, .. } => {
93104
if egui.is_quit_event(&event) {
94-
*control_flow = glium::glutin::event_loop::ControlFlow::Exit;
105+
*control_flow = glutin::event_loop::ControlFlow::Exit;
106+
}
107+
108+
if let glutin::event::WindowEvent::Resized(physical_size) = event {
109+
gl_window.resize(physical_size);
95110
}
96111

97112
egui.on_event(&event);
98113

99-
display.gl_window().window().request_redraw(); // TODO: ask egui if the events warrants a repaint instead
114+
gl_window.window().request_redraw(); // TODO: ask egui if the events warrants a repaint instead
115+
}
116+
glutin::event::Event::LoopDestroyed => {
117+
egui.destruct(&gl);
100118
}
101119

102120
_ => (),

0 commit comments

Comments
 (0)