i think i'm sticking with glfw until i change my mind lol
This commit is contained in:
parent
ceac5a09bb
commit
06bee7d20c
8 changed files with 152 additions and 26 deletions
54
Cargo.lock
generated
54
Cargo.lock
generated
|
|
@ -402,6 +402,15 @@ version = "0.2.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
|
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cmake"
|
||||||
|
version = "0.1.54"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e7caa3f9de89ddbe2c607f4101924c5abec803763ae9534e4f4d7d8f84aa81f0"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "colored"
|
name = "colored"
|
||||||
version = "2.2.0"
|
version = "2.2.0"
|
||||||
|
|
@ -844,6 +853,28 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "glfw"
|
||||||
|
version = "0.59.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c8c61a3f08ac5eb93c8dc0e9f2e6b2c7a7d14da089db39d43d696bc4fd025d4c"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 1.3.2",
|
||||||
|
"glfw-sys",
|
||||||
|
"objc2",
|
||||||
|
"raw-window-handle",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "glfw-sys"
|
||||||
|
version = "5.0.0+3.3.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1dfc32d45fb58ff38b112696907963a7d671e9cf742b16f882062169a053cf88"
|
||||||
|
dependencies = [
|
||||||
|
"cmake",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "glib"
|
name = "glib"
|
||||||
version = "0.21.0"
|
version = "0.21.0"
|
||||||
|
|
@ -1238,6 +1269,7 @@ dependencies = [
|
||||||
name = "moonhare_window"
|
name = "moonhare_window"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"glfw",
|
||||||
"gtk4",
|
"gtk4",
|
||||||
"moonhare_event",
|
"moonhare_event",
|
||||||
"moonhare_log",
|
"moonhare_log",
|
||||||
|
|
@ -2362,6 +2394,22 @@ dependencies = [
|
||||||
"web-sys",
|
"web-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi"
|
||||||
|
version = "0.3.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||||
|
dependencies = [
|
||||||
|
"winapi-i686-pc-windows-gnu",
|
||||||
|
"winapi-x86_64-pc-windows-gnu",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi-i686-pc-windows-gnu"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi-util"
|
name = "winapi-util"
|
||||||
version = "0.1.9"
|
version = "0.1.9"
|
||||||
|
|
@ -2371,6 +2419,12 @@ dependencies = [
|
||||||
"windows-sys 0.59.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi-x86_64-pc-windows-gnu"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-sys"
|
name = "windows-sys"
|
||||||
version = "0.45.0"
|
version = "0.45.0"
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ impl Default for Game {
|
||||||
Self {
|
Self {
|
||||||
is_running: true,
|
is_running: true,
|
||||||
name: default_game_name(),
|
name: default_game_name(),
|
||||||
context: WindowRenderContext::OPENGLWINIT
|
context: WindowRenderContext::OPENGLGLFW
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,4 +8,5 @@ authors.workspace = true
|
||||||
moonhare_log = { path = "../moonhare_log" }
|
moonhare_log = { path = "../moonhare_log" }
|
||||||
moonhare_event = { path = "../moonhare_event" }
|
moonhare_event = { path = "../moonhare_event" }
|
||||||
gtk4 = "*"
|
gtk4 = "*"
|
||||||
winit = "0.30"
|
winit = "0.30"
|
||||||
|
glfw = "*"
|
||||||
|
|
@ -7,14 +7,14 @@ pub enum WindowRenderContext {
|
||||||
VULKANGTK, // TODO
|
VULKANGTK, // TODO
|
||||||
OPENGLGTK,
|
OPENGLGTK,
|
||||||
OPENGLWINIT,
|
OPENGLWINIT,
|
||||||
|
OPENGLGLFW,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait WindowResult {
|
pub trait WindowResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait MoonhareWindow {
|
pub trait MoonhareWindow {
|
||||||
type WindowResult;
|
fn init();
|
||||||
fn init() -> Self::WindowResult;
|
|
||||||
fn on_update();
|
fn on_update();
|
||||||
fn shutdown();
|
fn shutdown();
|
||||||
}
|
}
|
||||||
|
|
@ -33,23 +33,21 @@ impl Window {
|
||||||
todo!()
|
todo!()
|
||||||
},
|
},
|
||||||
WindowRenderContext::OPENGLGTK => {
|
WindowRenderContext::OPENGLGTK => {
|
||||||
use std::thread;
|
todo!()
|
||||||
|
|
||||||
use gtk4::gio::prelude::ApplicationExtManual;
|
|
||||||
|
|
||||||
use crate::platforms::gtk_window::GTKWindow;
|
|
||||||
|
|
||||||
thread::spawn(|| {
|
|
||||||
moonhare_log::info("Created GTK Window thread");
|
|
||||||
let application = GTKWindow::init();
|
|
||||||
application.get_application().run();
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
WindowRenderContext::OPENGLWINIT => {
|
WindowRenderContext::OPENGLWINIT => {
|
||||||
use crate::platforms::winit_window::WinitWindow;
|
use crate::platforms::winit_window::WinitWindow;
|
||||||
|
|
||||||
moonhare_log::info("Creating Winit OpenGL Winit");
|
moonhare_log::info("Creating Winit OpenGL Window");
|
||||||
let application = WinitWindow::init();
|
WinitWindow::init();
|
||||||
|
},
|
||||||
|
WindowRenderContext::OPENGLGLFW => {
|
||||||
|
std::thread::spawn(|| {
|
||||||
|
use crate::platforms::glfw_window::GLFWWindow;
|
||||||
|
moonhare_log::info("Creating GLFW OpenGL Window");
|
||||||
|
GLFWWindow::init();
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
77
crates/moonhare_window/src/platforms/glfw_window.rs
Normal file
77
crates/moonhare_window/src/platforms/glfw_window.rs
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use glfw::{Context, Glfw, GlfwReceiver, PWindow, WindowEvent};
|
||||||
|
use gtk4::gdk::Key;
|
||||||
|
use moonhare_event::{event::{self, Event}, events::window_events::window_close_event::WindowCloseEvent};
|
||||||
|
|
||||||
|
use crate::{window_config, MoonhareWindow};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct GLFWWindow {
|
||||||
|
glfw_window: PWindow,
|
||||||
|
events: GlfwReceiver<(f64, WindowEvent)>,
|
||||||
|
glfw: Glfw,
|
||||||
|
is_running: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
const APP_ID: &str = "de.lunarakai.moonhare_engine";
|
||||||
|
|
||||||
|
impl GLFWWindow {
|
||||||
|
fn new() -> Self {
|
||||||
|
let mut glfw = glfw::init(glfw::fail_on_errors).unwrap();
|
||||||
|
let config = window_config::WindowConfig::default();
|
||||||
|
let (mut window, events) = glfw.create_window(
|
||||||
|
config.width,
|
||||||
|
config.height,
|
||||||
|
format!("{} GLFW", config.title).as_str(),
|
||||||
|
glfw::WindowMode::Windowed)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
window.set_key_polling(true);
|
||||||
|
window.make_current();
|
||||||
|
|
||||||
|
Self {
|
||||||
|
glfw_window: window,
|
||||||
|
events: events,
|
||||||
|
glfw: glfw,
|
||||||
|
is_running: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_window(&mut self) {
|
||||||
|
while !self.glfw_window.should_close() {
|
||||||
|
self.glfw.poll_events();
|
||||||
|
for(_, event) in glfw::flush_messages(&self.events) {
|
||||||
|
Self::handle_window_event(&mut self.glfw_window, event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_window_event(window: &mut glfw::Window, event: glfw::WindowEvent) {
|
||||||
|
match event {
|
||||||
|
glfw::WindowEvent::Close => {
|
||||||
|
WindowCloseEvent::emit();
|
||||||
|
}
|
||||||
|
_ => {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MoonhareWindow for GLFWWindow {
|
||||||
|
fn init() {
|
||||||
|
let mut window = GLFWWindow::new();
|
||||||
|
GLFWWindow::run_window(&mut window);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn on_update() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fn shutdown() {
|
||||||
|
// todo: emit WindowCloseEvent
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -39,15 +39,14 @@ impl GTKWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MoonhareWindow for GTKWindow {
|
impl MoonhareWindow for GTKWindow {
|
||||||
type WindowResult = GTKWindow;
|
fn init() {
|
||||||
fn init() -> Self::WindowResult {
|
|
||||||
let app = Application::builder().application_id(APP_ID).build();
|
let app = Application::builder().application_id(APP_ID).build();
|
||||||
|
|
||||||
app.connect_activate(GTKWindow::build_ui);
|
app.connect_activate(GTKWindow::build_ui);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
application: app
|
application: app
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
pub mod gtk_window;
|
pub mod gtk_window;
|
||||||
pub mod winit_window;
|
pub mod winit_window;
|
||||||
|
pub mod glfw_window;
|
||||||
|
|
@ -61,15 +61,11 @@ impl ApplicationHandler for WinitWindow {
|
||||||
|
|
||||||
|
|
||||||
impl MoonhareWindow for WinitWindow {
|
impl MoonhareWindow for WinitWindow {
|
||||||
type WindowResult = WinitWindow;
|
fn init() {
|
||||||
fn init() -> Self::WindowResult {
|
|
||||||
let event_loop = EventLoop::new().unwrap();
|
let event_loop = EventLoop::new().unwrap();
|
||||||
event_loop.set_control_flow(ControlFlow::Poll);
|
event_loop.set_control_flow(ControlFlow::Poll);
|
||||||
let mut app = WinitWindow::default();
|
let mut app = WinitWindow::default();
|
||||||
let _ = event_loop.run_app(&mut app);
|
let _ = event_loop.run_app(&mut app);
|
||||||
|
|
||||||
// Need to find a better way because this will not return until the window is closed
|
|
||||||
app
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue