#opengl #sdl2 #egui

egui-sdl2

egui integration for SDL2: event handling and software, OpenGL, or wgpu rendering

25 releases (12 breaking)

new 0.13.0 Nov 26, 2026
0.12.1 Oct 18, 2026
0.7.0 Jul 30, 2026
0.2.6 Mar 30, 2026
0.2.5 Oct 10, 2025

#879 in GUI

Download history 104/week @ 2026-08-09 45/week @ 2026-08-16 59/week @ 2026-08-23 44/week @ 2026-08-30 62/week @ 2026-09-06 45/week @ 2026-09-13 71/week @ 2026-09-20 111/week @ 2026-09-27 40/week @ 2026-10-04 52/week @ 2026-10-11 21/week @ 2026-10-18 31/week @ 2026-10-25 36/week @ 2026-11-01 62/week @ 2026-11-08 87/week @ 2026-11-15 65/week @ 2026-11-22

252 downloads per month

MIT/Apache

165KB
3K SLoC

CI Documentation Dependencies crates.io Downloads License

egui-sdl2

egui on SDL2: SDL2 event handling plus three swappable rendering backends behind one consistent API.

egui-sdl2 demo

Why egui-sdl2?

  • Three rendering backends, one API. Software (Canvas), OpenGL (glow), and WebGPU (wgpu) — pick one with a feature flag and use the same on_event / run / paint loop for all of them.
  • Tracks the latest egui. Kept in step with current egui releases so you are not stuck on an old version.
  • Built on the official design. Mirrors the structure of the upstream egui-winit, egui_glow, and egui-wgpu crates, so the API feels familiar and behaves predictably.
  • Batteries included. Translates SDL2 events into egui events and handles egui::PlatformOutput (clipboard, cursor updates, opening links). Both egui and sdl2 are re-exported for convenience, and the sdl2 re-export forwards all of SDL2's feature flags.

Rendering backends

Enable exactly what you need via feature flags:

  • canvas-backend — software rendering via Canvas
  • glow-backend — OpenGL via glow
  • wgpu-backend — WebGPU via wgpu

Or let it pick

EguiWindow owns the window and walks a list of renderers, keeping the first that comes up. A device with missing or broken GL drivers falls through to SDL's renderer and still shows a UI instead of exiting:

let mut egui = egui_sdl2::EguiWindow::new(
    &video,
    "Egui SDL2",
    (800, 600),
    |builder| { builder.resizable(); },
    &egui_sdl2::Renderer::FALLBACK_CHAIN, // GLES 3.0, then GL 3.2 core, then Canvas
)?;
println!("running on {:?}", egui.renderer());

loop {
    for event in event_pump.poll_iter() {
        egui.on_event(&event);
    }
    egui.run(|ctx: &egui::Context| {});
    egui.paint([0.1, 0.1, 0.1, 1.0]); // clears, paints and presents
}

Usage

// Create SDL2 window and canvas:
let sdl = sdl2::init().unwrap();
let video = sdl.video().unwrap();
let window = video.window("Egui SDL2 Canvas", 800, 600).build().unwrap();
let mut canvas = window.into_canvas().build().unwrap();
// Create egui renderer; the canvas stays yours:
let mut egui = egui_sdl2::EguiCanvas::new(&canvas);
let mut event_pump = sdl.event_pump().unwrap();
loop {
    // Feed SDL2 events into egui:
    for event in event_pump.poll_iter() {
        egui.on_event(&canvas, &event);
    }
    // Call `run` + `paint` each frame, over anything you drew yourself:
    egui.run(|ctx: &egui::Context| {});
    canvas.clear();
    egui.paint(&mut canvas);
    canvas.present();
    std::thread::sleep(std::time::Duration::from_secs_f64(1.0 / 60.0));
}

To get started, create an EguiGlow, EguiCanvas, or EguiWgpu instance to manage rendering. Pass SDL2 events to on_event, then call run and paint each frame. For event handling only, you can use the State type.

Examples are available in the examples/ directory. To run the canvas example:

cargo run --example canvas

The window example shows the picking path; RENDERER=canvas cargo run --example window forces the fallback.

License

Licensed under either of Apache License 2.0 or MIT license at your option.

Dependencies

~41–67MB
~1.5M SLoC