1extern crate gfx;
15extern crate gfx_window_sdl;
16extern crate sdl2;
17
18use gfx::Device;
19use sdl2::event::Event;
20use sdl2::keyboard::Keycode;
21use gfx::format::{Rgba8, DepthStencil};
22
23const CLEAR_COLOR: [f32; 4] = [0.1, 0.2, 0.3, 1.0];
24
25pub fn main() {
26 let sdl_context = sdl2::init().unwrap();
27 let video = sdl_context.video().unwrap();
28 video.gl_attr().set_context_profile(sdl2::video::GLProfile::Core);
30 video.gl_attr().set_context_version(3, 2);
31 let builder = video.window("SDL Window", 1024, 768);
32 let (window, _gl_context, mut device, mut factory, main_color, _main_depth) =
33 gfx_window_sdl::init::<Rgba8, DepthStencil>(&video, builder).unwrap();
34
35 let mut encoder: gfx::Encoder<_, _> = factory.create_command_buffer().into();
36
37 let mut events = sdl_context.event_pump().unwrap();
38
39 let mut running = true;
40 while running {
41 for event in events.poll_iter() {
43 match event {
44 Event::Quit { .. } |
45 Event::KeyUp { keycode: Some(Keycode::Escape), .. } => {
46 running = false;
47 }
48 _ => {}
49 }
50 }
51
52 encoder.clear(&main_color, CLEAR_COLOR);
54 encoder.flush(&mut device);
56 window.gl_swap_window();
57 device.cleanup();
58 }
59}