opengl window
This commit is contained in:
parent
33440da8f7
commit
30ff2325f2
8 changed files with 367 additions and 102 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use moonhare_window::{window_config, winit_window::{self, WinitWindow}};
|
||||
use moonhare_window::{window_config, MoonhareWindow};
|
||||
|
||||
use crate::{basic::node::Node, Game};
|
||||
|
||||
|
|
@ -9,7 +9,7 @@ pub struct GameWindow {
|
|||
pub height: u32,
|
||||
pub visble: bool,
|
||||
pub decorations: bool,
|
||||
pub winit_window: Option<WinitWindow>,
|
||||
pub winit_window: Option<MoonhareWindow>,
|
||||
}
|
||||
|
||||
impl Node for GameWindow {
|
||||
|
|
@ -39,9 +39,10 @@ impl GameWindow {
|
|||
window_config.visble = window.visble;
|
||||
window_config.decorations = window.decorations;
|
||||
|
||||
let winit = winit_window::WinitWindow::new(window_config);
|
||||
let _w = moonhare_window::MoonhareWindow::define_context(moonhare_window::WindowRenderContext::OPENGL);
|
||||
_w.create_window_from_context();
|
||||
|
||||
window.winit_window = Some(winit);
|
||||
window.winit_window = Some(_w);
|
||||
// todo: tell winit to create a window for us
|
||||
moonhare_log::info(format!("created window {:?}", window));
|
||||
window
|
||||
|
|
|
|||
|
|
@ -5,5 +5,6 @@ version.workspace = true
|
|||
authors.workspace = true
|
||||
|
||||
[dependencies]
|
||||
winit = "0.30.12"
|
||||
ash = "0.38"
|
||||
glium = "0.36"
|
||||
moonhare_log = { path = "../moonhare_log" }
|
||||
|
|
@ -1,3 +1,35 @@
|
|||
//! Provides an abstraction above Winit functionality
|
||||
//! Provides functionality to create either a vulkan or opengl window
|
||||
|
||||
use crate::opengl_window::create_open_gl_window;
|
||||
pub mod window_config;
|
||||
pub mod winit_window;
|
||||
pub mod opengl_window;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum WindowRenderContext {
|
||||
VULKAN, // TODO
|
||||
OPENGL,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct MoonhareWindow {
|
||||
render_context: WindowRenderContext
|
||||
}
|
||||
|
||||
impl MoonhareWindow {
|
||||
pub fn define_context(context: WindowRenderContext) -> Self {
|
||||
Self {
|
||||
render_context: context
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_window_from_context(self) {
|
||||
match self.render_context {
|
||||
WindowRenderContext::VULKAN => {
|
||||
todo!("Vulkan not implemented yet")
|
||||
},
|
||||
WindowRenderContext::OPENGL => {
|
||||
create_open_gl_window();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
32
crates/moonhare_window/src/opengl_window.rs
Normal file
32
crates/moonhare_window/src/opengl_window.rs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
use glium::{winit::dpi::{LogicalPosition, LogicalSize}, Surface};
|
||||
|
||||
use crate::window_config::WindowConfig;
|
||||
|
||||
pub fn create_open_gl_window() {
|
||||
let event_loop = glium::winit::event_loop::EventLoopBuilder::new().build().expect("event loop building");
|
||||
let (mut _window, display) = glium::backend::glutin::SimpleWindowBuilder::new().build(&event_loop);
|
||||
|
||||
let config = WindowConfig::default();
|
||||
_window.set_title(format!("{} OpenGL", &config.title).as_str());
|
||||
_window.set_decorations(config.decorations);
|
||||
_window.set_visible(config.visble);
|
||||
//_window.set_min_inner_size(Some(LogicalSize::new(config.width, config.height)));
|
||||
|
||||
|
||||
let mut frame = display.draw();
|
||||
frame.clear_color(0.0, 0.0, 1.0, 1.0);
|
||||
frame.finish().unwrap();
|
||||
|
||||
let _ = event_loop.run(move | event, window_target| {
|
||||
match event {
|
||||
glium::winit::event::Event::WindowEvent { event, .. } => match event {
|
||||
glium::winit::event::WindowEvent::CloseRequested => {
|
||||
window_target.exit()
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
0
crates/moonhare_window/src/vulkan_window.rs
Normal file
0
crates/moonhare_window/src/vulkan_window.rs
Normal file
|
|
@ -1,62 +0,0 @@
|
|||
use winit::{application::ApplicationHandler, dpi::LogicalSize, event::WindowEvent, event_loop::{self, ActiveEventLoop, EventLoop}, window::{Window, WindowAttributes}};
|
||||
|
||||
use crate::window_config::WindowConfig;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct WinitWindow {
|
||||
pub window: Window,
|
||||
}
|
||||
|
||||
impl WinitWindow {
|
||||
pub fn new(config: WindowConfig) -> Self {
|
||||
moonhare_log::trace("Im inside the create window function in winit");
|
||||
let event_loop = EventLoop::new().unwrap();
|
||||
let mut window_attributes = WindowAttributes::default()
|
||||
.with_title(config.title);
|
||||
|
||||
let logical_size = LogicalSize::new(config.width, config.height);
|
||||
window_attributes = window_attributes.with_inner_size(logical_size);
|
||||
window_attributes = window_attributes.with_max_inner_size(logical_size);
|
||||
|
||||
// Set Visible
|
||||
window_attributes = window_attributes.with_visible(config.visble);
|
||||
window_attributes = window_attributes.with_decorations(config.decorations);
|
||||
|
||||
let window = match event_loop.create_window(window_attributes) {
|
||||
Ok(window) => window,
|
||||
Err(err) => {
|
||||
moonhare_log::error("Error creating window: {err}");
|
||||
return;
|
||||
},
|
||||
};
|
||||
|
||||
moonhare_log::info(format!("Winit WIndow: {:?}", window));
|
||||
|
||||
Self { window: window }
|
||||
}
|
||||
}
|
||||
|
||||
impl ApplicationHandler for WinitWindow {
|
||||
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
|
||||
}
|
||||
|
||||
fn window_event(
|
||||
&mut self,
|
||||
event_loop: &ActiveEventLoop,
|
||||
window_id: winit::window::WindowId,
|
||||
event: winit::event::WindowEvent,
|
||||
) {
|
||||
match event {
|
||||
WindowEvent::CloseRequested => {
|
||||
event_loop.exit();
|
||||
},
|
||||
WindowEvent::RedrawRequested => {
|
||||
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue