2019-09-26 16:47:04 +10:00
|
|
|
use pixels::{Error, Pixels};
|
2019-09-26 16:07:30 +10:00
|
|
|
use winit::event;
|
|
|
|
use winit::event_loop::{ControlFlow, EventLoop};
|
|
|
|
|
2019-09-26 16:47:04 +10:00
|
|
|
fn main() -> Result<(), Error> {
|
2019-09-26 16:07:30 +10:00
|
|
|
env_logger::init();
|
|
|
|
let event_loop = EventLoop::new();
|
|
|
|
|
|
|
|
let (_window, surface) = {
|
|
|
|
let window = winit::window::Window::new(&event_loop).unwrap();
|
|
|
|
let surface = wgpu::Surface::create(&window);
|
2019-09-26 16:11:36 +10:00
|
|
|
|
2019-09-26 16:07:30 +10:00
|
|
|
(window, surface)
|
|
|
|
};
|
|
|
|
|
|
|
|
let mut fb = Pixels::new(320, 240, &surface)?;
|
|
|
|
|
|
|
|
event_loop.run(move |event, _, control_flow| match event {
|
|
|
|
event::Event::WindowEvent { event, .. } => match event {
|
|
|
|
event::WindowEvent::KeyboardInput {
|
|
|
|
input:
|
|
|
|
event::KeyboardInput {
|
|
|
|
virtual_keycode: Some(event::VirtualKeyCode::Escape),
|
|
|
|
state: event::ElementState::Pressed,
|
|
|
|
..
|
|
|
|
},
|
|
|
|
..
|
|
|
|
}
|
|
|
|
| event::WindowEvent::CloseRequested => {
|
|
|
|
*control_flow = ControlFlow::Exit;
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
},
|
|
|
|
event::Event::EventsCleared => {
|
|
|
|
fb.render();
|
|
|
|
}
|
|
|
|
_ => (),
|
|
|
|
});
|
|
|
|
}
|