diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index e7a11a9..531a4ce 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,44 @@ -fn main() { - println!("Hello, world!"); +extern crate sdl2; + +use sdl2::pixels::Color; +use sdl2::event::Event; +use sdl2::keyboard::Keycode; +use std::time::Duration; + +static WIDTH : u32 = 32; +static HEIGHT : u32 = 64; +static SCALE : u32 = 10; + + +pub fn main() { + let sdl_context = sdl2::init().unwrap(); + let video_subsystem = sdl_context.video().unwrap(); + + let window = video_subsystem.window("CHIP-8", WIDTH * SCALE, HEIGHT * SCALE) + .position_centered() + .build() + .unwrap(); + + let mut canvas = window.into_canvas().build().unwrap(); + + canvas.set_draw_color(Color::RGB(255, 255, 255)); + canvas.clear(); + canvas.present(); + let mut event_pump = sdl_context.event_pump().unwrap(); + 'running: loop { + for event in event_pump.poll_iter() { + match event { + Event::Quit {..} | + Event::KeyDown { keycode: Some(Keycode::Escape), .. } => { + break 'running + }, + _ => {} + } + } + // The rest of the game loop goes here... + + canvas.clear(); + canvas.present(); + std::thread::sleep(Duration::new(0, 1_000_000_000u32 / 60)); + } } |