Skip to content

Instantly share code, notes, and snippets.

@mikebenfield
Last active August 29, 2017 00:09
Show Gist options
  • Save mikebenfield/2f19295012c5ee96a0dcb0ae305732cd to your computer and use it in GitHub Desktop.
Save mikebenfield/2f19295012c5ee96a0dcb0ae305732cd to your computer and use it in GitHub Desktop.
extern crate sdl2;
extern crate gl;
fn find_sdl_gl_driver() -> Option<u32> {
for (index, item) in sdl2::render::drivers().enumerate() {
if item.name == "opengl" {
return Some(index as u32);
}
}
None
}
fn main() {
let sdl_context = sdl2::init().unwrap();
let video_subsystem = sdl_context.video().unwrap();
video_subsystem.gl_attr().set_context_major_version(4);
video_subsystem.gl_attr().set_context_minor_version(1);
let window = video_subsystem.window("Window", 800, 600)
.opengl()
.build()
.unwrap();
let canvas = window.into_canvas()
.index(find_sdl_gl_driver().unwrap())
.build()
.unwrap();
canvas.window().gl_set_context_to_current().unwrap();
gl::load_with(|name| video_subsystem.gl_get_proc_address(name) as *const _);
unsafe {
println!("{}", gl::GetIntegerv::is_loaded());
let mut major = 102i32;
gl::GetIntegerv(gl::MAJOR_VERSION, &mut major);
let mut minor = 304i32;
gl::GetIntegerv(gl::MINOR_VERSION, &mut minor);
println!("Version {}.{}", major, minor);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment