ArjunNair / egui_sdl2_gl

Egui backend for SDL2 + OpenGL
MIT License
52 stars 35 forks source link

Panel backgrounds render, but nothing else does #35

Closed alexispurslane closed 9 months ago

alexispurslane commented 11 months ago

I have a project that is using sdl2 and raw opengl that I want to integrate this crate into so I can use egui, but unfortunately even after following the examples I can't get anything but the panel backgrounds to render. So for instance, if I make a full screen panel the whole screen becomes gray, and if I make a bottom panel then a line along the bottom of the screen becomes gray (while the rest of the screen shows the other stuff I'm rendering), but none of the labels or interface widgets that I add to the panels actually render. Here's the basic layout of my code:

let sdl_context = sdl2::init().unwrap();
    let video_subsystem = sdl_context.video().unwrap();

    let gl_attr = video_subsystem.gl_attr();
    // set up opengl settings

    let mut window = video_subsystem
        .window("window title", 1920, 1080)
        .opengl()
        .build()
        .unwrap();

    ///////// Initialize OpenGL

    let _image_context = sdl2::image::init(sdl2::image::InitFlag::all());
    let _gl_context = window.gl_create_context().unwrap();
    let _gl =
        gl::load_with(|s| video_subsystem.gl_get_proc_address(s) as *const std::os::raw::c_void);

    unsafe {
        gl::Viewport(0, 0, w as gl::types::GLint, h as gl::types::GLint);
        gl::ClearColor(0.0, 0.0, 0.0, 1.0);
        gl::Enable(gl::DEPTH_TEST);
    }

    ///////// Initialize eGUI

    let shader_ver = ShaderVersion::Default;
    let (mut painter, mut egui_state) =
        egui_backend::with_sdl2(&window, shader_ver, egui_sdl2_gl::DpiScaling::Default);

    let mut egui_ctx = egui::Context::default();

   // ...

   loop {
        egui_state.input.time = Some(start_time.elapsed().as_secs_f64());
        // clear screen
        // render other opengl stuff
        egui_ctx.begin_frame(egui_state.input.take());
        egui::TopBottomPanel::bottom("bottom_panel").show(&egui_ctx, |ui| {
            ui.label("Hello world");
        });

        let FullOutput {
            platform_output,
            repaint_after,
            textures_delta,
            shapes,
        } = egui_ctx.end_frame();

        egui_state.process_output(&window, &platform_output);

        let paint_jobs = egui_ctx.tessellate(shapes);
        painter.paint_jobs(None, textures_delta, paint_jobs);

        window.gl_swap_window();
    }

And here's a link to my actual code: https://github.com/alexispurslane/opengl-project/blob/7d57cc212feb73e006457670f589e5f29423729d/src/main.rs#L32

Is there something wrong with the order I'm doing things in, or a step I'm missing? Or maybe some dependency I've left out? I'm suffering from some serious neurological problems right now so I'm sure it's some silly mistake I've missed. Thank you for your help! :D

P.S. I'm honestly really lucky to have found a relatively actively maintained project that slots so perfectly into the intersection of technologies I'm already using, so I really appreciate the work you are doing.

novara754 commented 9 months ago

See #32. You need to disable depth testing before rendering the egui portion of your app. You can re-enable depth testing for your other renders.

alexispurslane commented 9 months ago

Ohhhhhh thanks!