Create a window
This commit is contained in:
parent
cdc67e63dc
commit
311332c6d8
25
src/app.rs
Normal file
25
src/app.rs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
use anyhow::Result;
|
||||||
|
use winit::window::Window;
|
||||||
|
|
||||||
|
/// Our Vulkan app.
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct App {}
|
||||||
|
|
||||||
|
impl App {
|
||||||
|
/// Creates our Vulkan app.
|
||||||
|
pub unsafe fn create(window: &Window) -> Result<Self> {
|
||||||
|
Ok(Self {})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Renders a frame for our Vulkan app.
|
||||||
|
pub unsafe fn render(&mut self, window: &Window) -> Result<()> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Destroys our Vulkan app.
|
||||||
|
pub unsafe fn destroy(&mut self) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The Vulkan handles and associated properties used by our Vulkan app.
|
||||||
|
#[derive(Clone, Debug, Default)]
|
||||||
|
pub struct AppData {}
|
50
src/main.rs
50
src/main.rs
@ -1,3 +1,49 @@
|
|||||||
fn main() {
|
#![allow(
|
||||||
println!("Hello, world!");
|
dead_code,
|
||||||
|
unused_variables,
|
||||||
|
clippy::too_many_arguments,
|
||||||
|
clippy::unnecessary_wraps
|
||||||
|
)]
|
||||||
|
|
||||||
|
mod app;
|
||||||
|
use app::{App, AppData};
|
||||||
|
|
||||||
|
use anyhow::Result;
|
||||||
|
use winit::dpi::LogicalSize;
|
||||||
|
use winit::event::{Event, WindowEvent};
|
||||||
|
use winit::event_loop::{ControlFlow, EventLoop};
|
||||||
|
use winit::window::{Window, WindowBuilder};
|
||||||
|
|
||||||
|
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 = unsafe { App::create(&window)? };
|
||||||
|
let mut destorying = 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 !destorying => unsafe { app.render(&window) }.unwrap(),
|
||||||
|
// Destroy our Vulkan app.
|
||||||
|
Event::WindowEvent {
|
||||||
|
event: WindowEvent::CloseRequested,
|
||||||
|
..
|
||||||
|
} => {
|
||||||
|
destorying = true;
|
||||||
|
*control_flow = ControlFlow::Exit;
|
||||||
|
unsafe {
|
||||||
|
app.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user