/glium-sdl2

An SDL2 backend for Glium

Primary LanguageRustApache License 2.0Apache-2.0

glium_sdl2

Build Status Latest Version

An SDL2 backend for Glium - a high-level OpenGL wrapper for the Rust language.

This library, along with glium and rust-sdl2, are in heavy development and are subject to change.

[dependencies]
glium_sdl2 = "0.12"
sdl2 = "0.19"
glium = "0.14"

features = []
default-features = false

glium_sdl2 doesn't reexport the glium or sdl2 crates, so you must declare them with the versions listed above in your Cargo.toml file.

glium_sdl2 will be bumped to 0.13, 0.14, etc. once this library, glium or sdl2 make breaking changes.

Example usage

Using glium with SDL2 is very similar to using glium with glutin. Generally speaking, Glium documentation and tutorials should be fairly trivial to adapt to SDL2.

#[macro_use]
extern crate glium;

extern crate glium_sdl2;
extern crate sdl2;

fn main() {
    use glium_sdl2::DisplayBuild;

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

    let display = video_subsystem.window("My window", 800, 600)
        .resizable()
        .build_glium()
        .unwrap();

    let mut running = true;
    let mut event_pump = sdl_context.event_pump().unwrap();

    while running {
        let mut target = display.draw();
        // do drawing here...
        target.finish().unwrap();

        // Event loop: includes all windows

        for event in event_pump.poll_iter() {
            use sdl2::event::Event;

            match event {
                Event::Quit { .. } => {
                    running = false;
                },
                _ => ()
            }
        }
    }
}

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.