WINIT WINDOW!!!!
This commit is contained in:
parent
b777761d54
commit
f9863934d5
4 changed files with 62 additions and 2 deletions
|
@ -4,6 +4,7 @@ version = "0.1.0"
|
|||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.93"
|
||||
chrono = "0.4.38"
|
||||
colored = "2.1.0"
|
||||
lazy_static = "1.5.0"
|
||||
|
@ -14,3 +15,5 @@ reedline = "0.37.0"
|
|||
regex = "1.11.1"
|
||||
thiserror = "2.0.3"
|
||||
tokio = { version = "1.41.1", features = ["macros", "rt", "rt-multi-thread"] }
|
||||
wgpu = "23.0.1"
|
||||
winit = "0.30.5"
|
||||
|
|
|
@ -1,3 +1,16 @@
|
|||
pub mod commands;
|
||||
pub mod repl;
|
||||
pub mod splash;
|
||||
pub mod renderer;
|
||||
use anyhow::Result;
|
||||
use renderer::App;
|
||||
use winit::event_loop::{ControlFlow, EventLoop};
|
||||
|
||||
|
||||
|
||||
pub fn init_render() -> Result<()> {
|
||||
let event_loop = EventLoop::new().unwrap();
|
||||
event_loop.set_control_flow(ControlFlow::Poll);
|
||||
let mut app = App::default();
|
||||
Ok(event_loop.run_app(&mut app)?)
|
||||
}
|
43
engine/src/core/renderer/mod.rs
Normal file
43
engine/src/core/renderer/mod.rs
Normal file
|
@ -0,0 +1,43 @@
|
|||
use log2::{debug, error};
|
||||
use winit::application::ApplicationHandler;
|
||||
use winit::event::WindowEvent;
|
||||
use winit::event_loop::ActiveEventLoop;
|
||||
use winit::window::{Window, WindowId};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct App {
|
||||
window: Option<Window>,
|
||||
}
|
||||
|
||||
impl ApplicationHandler for App {
|
||||
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
|
||||
if self.window.is_none() {
|
||||
let win_attr = Window::default_attributes().with_title("Zenyx");
|
||||
let window = event_loop
|
||||
.create_window(win_attr)
|
||||
.expect("create window err.");
|
||||
self.window = Some(window);
|
||||
}
|
||||
}
|
||||
|
||||
fn window_event(
|
||||
&mut self,
|
||||
event_loop: &ActiveEventLoop,
|
||||
_window_id: WindowId,
|
||||
event: WindowEvent,
|
||||
) {
|
||||
match event {
|
||||
WindowEvent::CloseRequested => {
|
||||
event_loop.exit();
|
||||
debug!("Window closed, exiting");
|
||||
std::process::exit(0)
|
||||
}
|
||||
WindowEvent::Resized(size) => {
|
||||
let size_str: String = size.height.to_string() + "x" + &size.width.to_string();
|
||||
//self.window.as_ref().unwrap().set_title(&format!("you reszed the window to {size_str}"));
|
||||
debug!("Window resized to {:?}", size_str);
|
||||
}
|
||||
_ => error!("Unhandled window event"),
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
use std::io;
|
||||
|
||||
use anyhow::Result;
|
||||
use log2::info;
|
||||
|
||||
pub mod core;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), io::Error> {
|
||||
async fn main() -> Result<()> {
|
||||
let _log2 = log2::open("z.log").tee(true).level("trace").start();
|
||||
info!("Initalizing Engine");
|
||||
let shell_thread = tokio::task::spawn(async {
|
||||
|
@ -16,6 +16,7 @@ async fn main() -> Result<(), io::Error> {
|
|||
|
||||
core::splash::print_splash();
|
||||
info!("Engine Initalized");
|
||||
core::init_render()?;
|
||||
shell_thread.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue