1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
use ash::Entry;
use ash::Instance;
use ash::vk;
use ash_window::create_surface;
use raw_window_handle::HasDisplayHandle;
use raw_window_handle::HasWindowHandle;
use winit::application::ApplicationHandler;
use winit::event::WindowEvent;
use winit::event_loop::{ActiveEventLoop, EventLoop};
use winit::window::{Window, WindowId};
#[derive(Default)]
struct App {
window: Option<Window>,
entry: Option<Entry>,
vk_instance: Option<Instance>,
}
impl ApplicationHandler for App {
fn window_event(
&mut self,
event_loop: &ActiveEventLoop,
window_id: WindowId,
event: WindowEvent,
) {
match event {
WindowEvent::CloseRequested => {
event_loop.exit();
}
WindowEvent::RedrawRequested => {
println!("Redraw requested!");
}
WindowEvent::Resized(e) => {
println!("Received resize event, {:?}", event);
println!("New size: {:?}", e);
}
_ => {
println!("Received event: {:?}", event);
}
}
}
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
println!("Idk ig the app wants me to resume??");
let win = event_loop
.create_window(Window::default_attributes())
.unwrap();
unsafe {
self.entry = Some(Entry::load().unwrap());
let app_info = vk::ApplicationInfo {
api_version: vk::make_api_version(0, 1, 0, 0),
..Default::default()
};
let create_info = vk::InstanceCreateInfo {
p_application_info: &app_info,
..Default::default()
};
self.vk_instance = Some(self.entry.as_ref().unwrap().create_instance(&create_info, None).unwrap());
let _ = create_surface(
&self.entry.as_ref().unwrap(),
&self.vk_instance.as_ref().unwrap(),
win.display_handle().unwrap().as_raw(),
win.window_handle().unwrap().as_raw(),
None,
);
};
self.window = Some(win);
}
}
fn main() {
let event_loop = EventLoop::new().unwrap();
event_loop.set_control_flow(winit::event_loop::ControlFlow::Wait);
let _ = event_loop.run_app(&mut App::default());
}
|