Skip to content

Commit

Permalink
Rebased around the new egui_for_winit
Browse files Browse the repository at this point in the history
# Conflicts:
#	Cargo.lock
#	egui_glium/src/lib.rs
  • Loading branch information
AlexApps99 committed Sep 29, 2021
1 parent f2dd3df commit d763365
Show file tree
Hide file tree
Showing 15 changed files with 706 additions and 545 deletions.
88 changes: 23 additions & 65 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion egui_glium/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ all-features = true
egui = { version = "0.14.0", path = "../egui", default-features = false, features = ["single_threaded"] }
egui-winit = { version = "0.14.0", path = "../egui-winit", default-features = false }
epi = { version = "0.14.0", path = "../epi" }
glium = "0.30"
glutin = "0.27"
glow = "0.11"

# feature "persistence":
directories-next = { version = "2", optional = true }
Expand Down
86 changes: 52 additions & 34 deletions egui_glium/examples/pure.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//! Example how to use pure `egui_glium` without [`epi`].
use glium::glutin;

fn create_display(event_loop: &glutin::event_loop::EventLoop<()>) -> glium::Display {
fn create_display(
event_loop: &glutin::event_loop::EventLoop<()>,
) -> (
glutin::WindowedContext<glutin::PossiblyCurrent>,
glow::Context,
) {
let window_builder = glutin::window::WindowBuilder::new()
.with_resizable(true)
.with_inner_size(glutin::dpi::LogicalSize {
Expand All @@ -10,24 +13,37 @@ fn create_display(event_loop: &glutin::event_loop::EventLoop<()>) -> glium::Disp
})
.with_title("egui_glium example");

let context_builder = glutin::ContextBuilder::new()
.with_depth_buffer(0)
.with_srgb(true)
.with_stencil_buffer(0)
.with_vsync(true);

glium::Display::new(window_builder, context_builder, event_loop).unwrap()
let gl_window = unsafe {
glutin::ContextBuilder::new()
.with_depth_buffer(0)
.with_srgb(true)
.with_stencil_buffer(0)
.with_vsync(true)
.build_windowed(window_builder, event_loop)
.unwrap()
.make_current()
.unwrap()
};

let gl = unsafe { glow::Context::from_loader_function(|s| gl_window.get_proc_address(s)) };

unsafe {
use glow::HasContext;
gl.enable(glow::FRAMEBUFFER_SRGB);
}

(gl_window, gl)
}

fn main() {
let event_loop = glutin::event_loop::EventLoop::with_user_event();
let display = create_display(&event_loop);
let (gl_window, gl) = create_display(&event_loop);

let mut egui = egui_glium::EguiGlium::new(&display);
let mut egui = egui_glium::EguiGlium::new(&gl_window, &gl);

event_loop.run(move |event, _, control_flow| {
let mut redraw = || {
egui.begin_frame(&display);
egui.begin_frame(gl_window.window());

let mut quit = false;

Expand All @@ -49,36 +65,31 @@ fn main() {
});
});

let (needs_repaint, shapes) = egui.end_frame(&display);
let (needs_repaint, shapes) = egui.end_frame(gl_window.window());

*control_flow = if quit {
glutin::event_loop::ControlFlow::Exit
} else if needs_repaint {
display.gl_window().window().request_redraw();
gl_window.window().request_redraw();
glutin::event_loop::ControlFlow::Poll
} else {
glutin::event_loop::ControlFlow::Wait
};

{
use glium::Surface as _;
let mut target = display.draw();

let clear_color = egui::Rgba::from_rgb(0.1, 0.3, 0.2);
target.clear_color(
clear_color[0],
clear_color[1],
clear_color[2],
clear_color[3],
);

// draw things behind egui here

egui.paint(&display, &mut target, shapes);

// draw things on top of egui here

target.finish().unwrap();
unsafe {
use glow::HasContext;
gl.clear_color(
clear_color[0],
clear_color[1],
clear_color[2],
clear_color[3],
);
gl.clear(glow::COLOR_BUFFER_BIT);
}
egui.paint(&gl_window, &gl, shapes);
gl_window.swap_buffers().unwrap();
}
};

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

glutin::event::Event::WindowEvent { event, .. } => {
if egui.is_quit_event(&event) {
*control_flow = glium::glutin::event_loop::ControlFlow::Exit;
*control_flow = glutin::event_loop::ControlFlow::Exit;
}

if let glutin::event::WindowEvent::Resized(physical_size) = event {
gl_window.resize(physical_size);
}

egui.on_event(&event);

display.gl_window().window().request_redraw(); // TODO: ask egui if the events warrants a repaint instead
gl_window.window().request_redraw(); // TODO: ask egui if the events warrants a repaint instead
}
glutin::event::Event::LoopDestroyed => {
egui.destruct(&gl);
}

_ => (),
Expand Down
Loading

0 comments on commit d763365

Please sign in to comment.