vulkan-tutorial/src/main.rs

42 lines
1.2 KiB
Rust
Raw Normal View History

2023-04-05 10:48:25 -04:00
use ::anyhow::Result;
use ::winit::dpi::LogicalSize;
use ::winit::event::{Event, WindowEvent};
use ::winit::event_loop::{ControlFlow, EventLoop};
use ::winit::window::WindowBuilder;
2023-03-31 10:50:34 -04:00
2023-04-05 10:48:25 -04:00
use vulkan_tutorial::create_app;
2023-03-31 10:50:34 -04:00
fn main() -> Result<()> {
pretty_env_logger::init();
// Window
let event_loop = EventLoop::new();
let window = WindowBuilder::new()
.with_title("Vulkan Tutorial (Rust)")
.with_inner_size(LogicalSize::new(1024, 768))
.build(&event_loop)?;
// App
2023-04-05 10:48:25 -04:00
let mut app = create_app(&window)?;
2023-03-31 11:09:20 -04:00
let mut destroying = false;
2023-03-31 10:50:34 -04:00
event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Poll;
match event {
// Render a frame if our Vulkan app is not being destroyed
2023-03-31 11:09:20 -04:00
Event::MainEventsCleared if !destroying => unsafe { app.render(&window) }.unwrap(),
2023-03-31 10:50:34 -04:00
// Destroy our Vulkan app.
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} => {
2023-03-31 11:09:20 -04:00
destroying = true;
2023-03-31 10:50:34 -04:00
*control_flow = ControlFlow::Exit;
unsafe {
app.destroy();
}
}
_ => {}
}
});
2023-03-31 10:33:37 -04:00
}