Skip to content

abus-sh/egui-sdl3

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

90 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CI Documentation Dependencies crates.io Downloads

egui-sdl3

This crate provides integration between egui and sdl3, including event handling and multiple rendering backends with a consistent API. It supports optional rendering backends:

  • Software via Canvas (canvas-backend feature)
  • OpengGL via glow (glow-backend feature)
  • WebgGPU via wgpu (wgpu-backend feature)

The implementation is based on the design of the official egui-winit, egui_glow, egui-wgpu crates, aming to make it easy to use SDL3 with egui.

Both egui and sdl3 are re-exported for convenience. The sdl3 re-export includes all feature flags available to use.

Usage

// Create SDL3 window:
let sdl = sdl3::init().unwrap();
let video = sdl.video().unwrap();
let window = video.window("Egui SDL3 Canvas", 800, 600).build().unwrap();
// Create egui renderer:
let mut egui = egui_sdl3::EguiCanvas::new(window);
let mut event_pump = sdl.event_pump().unwrap();
loop {
    // Feed SDL3 events into egui:
    for event in event_pump.poll_iter() {
        egui.on_event(&event);
    }
    // Call `run` + `paint` each frame:
    egui.run(|ctx: &egui::Context| {});
    egui.paint();
    egui.present();
    std::thread::sleep(std::time::Duration::from_secs_f64(1.0 / 60.0));
}

To get started, create an EguiGlow or EguiCanvas or EguiWgpu instance to manage rendering. Pass SDL3 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

About

Integration between egui and SDL2: event handling and rendering via OpenGL, Canvas, WebGPU

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages