vulkan-tutorial/src/main.rs

42 lines
1.2 KiB
Rust

use ::anyhow::Result;
use ::winit::dpi::LogicalSize;
use ::winit::event::{Event, WindowEvent};
use ::winit::event_loop::{ControlFlow, EventLoop};
use ::winit::window::WindowBuilder;
use vulkan_tutorial::create_app;
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
let mut app = create_app(&window)?;
let mut destroying = false;
event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Poll;
match event {
// Render a frame if our Vulkan app is not being destroyed
Event::MainEventsCleared if !destroying => unsafe { app.render(&window) }.unwrap(),
// Destroy our Vulkan app.
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} => {
destroying = true;
*control_flow = ControlFlow::Exit;
unsafe {
app.destroy();
}
}
_ => {}
}
});
}