2021-32-bit-holiday-jam/src/main.rs

59 lines
1.2 KiB
Rust
Raw Normal View History

2020-01-06 01:25:17 +00:00
use gl::types::*;
use sdl2::event::Event;
use sdl2::keyboard::Keycode;
use std::time::Duration;
fn main () {
let sdl_context = sdl2::init ().unwrap ();
let video_subsystem = sdl_context.video ().unwrap ();
let window = video_subsystem.window ("OpenGL? In my Rust?", 1280, 720)
.position_centered ()
.opengl ()
.build ()
.unwrap ();
println! ("{:?}", &video_subsystem);
println! ("{}", video_subsystem.current_video_driver ());
gl::load_with (|s| {
let result = video_subsystem.gl_get_proc_address (s) as *const _;
//println! ("{:?}", result);
result
});
assert! (gl::ClearColor::is_loaded ());
let gl_ctx = window.gl_create_context ().unwrap ();
let mut event_pump = sdl_context.event_pump ().unwrap ();
'running: loop {
let mouse = event_pump.mouse_state ();
for event in event_pump.poll_iter() {
match event {
Event::Quit {..} |
Event::KeyDown { keycode: Some (Keycode::Escape), .. } => {
break 'running
},
_ => (),
}
}
window.gl_make_current (&gl_ctx).unwrap ();
unsafe {
gl::ClearColor (1.0f32, 0.0f32, 1.0f32, 1.0f32);
gl::Clear (gl::COLOR_BUFFER_BIT | gl::DEPTH_BUFFER_BIT);
}
window.gl_swap_window ();
::std::thread::sleep (Duration::from_millis (15));
}
}