Skip to content

Instantly share code, notes, and snippets.

@matthewjberger
Created June 6, 2018 04:51
Show Gist options
  • Save matthewjberger/76e12176453cbd6a1b6369982dd673f8 to your computer and use it in GitHub Desktop.
Save matthewjberger/76e12176453cbd6a1b6369982dd673f8 to your computer and use it in GitHub Desktop.
SDL2/OpenGl in Rust
[package]
name = "chapter-01"
version = "0.1.0"
authors = ["Matthew J. Berger <[email protected]>"]
[dependencies]
gl = "0.10.0"
[dependencies.sdl2]
version = "0.31.0"
features = ["bundled", "static-link"]
extern crate sdl2;
extern crate gl;
fn main() {
let sdl = sdl2::init().unwrap();
let video_subsystem = sdl.video().unwrap();
let window = video_subsystem
.window("Game", 900, 700)
.opengl()
.resizable()
.build()
.unwrap();
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::ClearColor(0.3, 0.3, 0.5, 1.0);
}
let mut event_pump = sdl.event_pump().unwrap();
'main: loop {
for event in event_pump.poll_iter() {
match event {
sdl2::event::Event::Quit {..} => break 'main,
_ => {},
}
}
unsafe {
gl::Clear(gl::COLOR_BUFFER_BIT);
}
window.gl_swap_window();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment