i'm blue dabededabeday
This commit is contained in:
parent
f5e9bca56b
commit
5a88e1c4c2
6 changed files with 66 additions and 19 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -1058,6 +1058,7 @@ version = "0.1.0"
|
||||||
name = "moonhare_game"
|
name = "moonhare_game"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"moonhare_graphics",
|
||||||
"moonhare_log",
|
"moonhare_log",
|
||||||
"moonhare_window",
|
"moonhare_window",
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -5,5 +5,6 @@ version.workspace = true
|
||||||
authors.workspace = true
|
authors.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
moonhare_graphics = { path = "../moonhare_graphics" }
|
||||||
moonhare_log = { path = "../moonhare_log" }
|
moonhare_log = { path = "../moonhare_log" }
|
||||||
moonhare_window = { path = "../moonhare_window" }
|
moonhare_window = { path = "../moonhare_window" }
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
//! Base functionality for a Moonhare Game Engine Project
|
//! Base functionality for a Moonhare Game Engine Project
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
use moonhare_graphics::glium::{backend::Context, glutin::api::egl::context};
|
||||||
use moonhare_log::*;
|
use moonhare_log::*;
|
||||||
use moonhare_window::{glfw::{self, PWindow}, platforms::glfw_window::GLFWWindow, Window, WindowRenderContext};
|
use moonhare_window::{glfw::PWindow, platforms::glfw_window::GLFWWindow};
|
||||||
|
|
||||||
pub mod basic;
|
pub mod basic;
|
||||||
|
|
||||||
/// Only one Game may exist per project
|
/// Only one Game may exist per project
|
||||||
|
|
@ -12,8 +12,8 @@ pub mod basic;
|
||||||
pub struct Game {
|
pub struct Game {
|
||||||
pub is_running: bool,
|
pub is_running: bool,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub context: WindowRenderContext,
|
pub context: moonhare_window::WindowRenderContext,
|
||||||
pub glfw_window: Option<GLFWWindow>
|
pub glfw_window: Option<moonhare_window::platforms::glfw_window::GLFWWindow>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Game {
|
impl Default for Game {
|
||||||
|
|
@ -21,7 +21,7 @@ impl Default for Game {
|
||||||
Self {
|
Self {
|
||||||
is_running: true,
|
is_running: true,
|
||||||
name: default_game_name(),
|
name: default_game_name(),
|
||||||
context: WindowRenderContext::OPENGLGLFW,
|
context: moonhare_window::WindowRenderContext::OPENGLGLFW,
|
||||||
glfw_window: None,
|
glfw_window: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -34,18 +34,28 @@ impl Game {
|
||||||
|
|
||||||
pub fn run(self) {
|
pub fn run(self) {
|
||||||
info("Running Game...");
|
info("Running Game...");
|
||||||
let mut glfw_window_unwrapped: GLFWWindow = self.glfw_window.unwrap();
|
let mut glfw_window_unwrapped: moonhare_window::platforms::glfw_window::GLFWWindow = self.glfw_window.unwrap();
|
||||||
|
let mut context: std::rc::Rc<moonhare_graphics::glium::backend::Context>;
|
||||||
|
|
||||||
|
context = moonhare_graphics::build_context(glfw_window_unwrapped.glfw_window);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
while self.is_running {
|
while self.is_running {
|
||||||
handle_window_event(&mut glfw_window_unwrapped);
|
let _ = move |mut window: GLFWWindow| {
|
||||||
|
handle_window_event(&mut window);
|
||||||
|
};
|
||||||
|
|
||||||
// update();
|
// update();
|
||||||
// render();
|
// render();
|
||||||
|
render(context.clone());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_window(&mut self) {
|
pub fn add_window(&mut self) {
|
||||||
moonhare_log::info(format!("Adding window to {:?}", self));
|
moonhare_log::info(format!("Adding window to {:?}", self));
|
||||||
self.glfw_window =Some(Window::create(self.context).into());
|
self.glfw_window =Some(moonhare_window::Window::create(self.context).into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -54,9 +64,15 @@ fn default_game_name() -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deals with GLFW Window Events (in `monhare_window`)
|
/// Deals with GLFW Window Events (in `monhare_window`)
|
||||||
fn handle_window_event(glfw_window: &mut GLFWWindow) {
|
fn handle_window_event(glfw_window: &mut moonhare_window::platforms::glfw_window::GLFWWindow) {
|
||||||
glfw_window.glfw_window.glfw.poll_events();
|
glfw_window.glfw_window.glfw.poll_events();
|
||||||
for (_, event) in glfw::flush_messages(&glfw_window.events) {
|
for (_, event) in moonhare_window::glfw::flush_messages(&glfw_window.events) {
|
||||||
GLFWWindow::handle_window_event(&mut glfw_window.glfw_window, event);
|
moonhare_window::platforms::glfw_window::GLFWWindow::handle_window_event(&mut glfw_window.glfw_window, event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn render(context: Rc<Context>) {
|
||||||
|
let mut target = moonhare_graphics::glium::Frame::new(context.clone(), context.get_framebuffer_dimensions());
|
||||||
|
moonhare_graphics::glium::Surface::clear_color(&mut target, 0.0, 0.0, 1.0, 1.0);
|
||||||
|
target.finish().unwrap();
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@ use moonhare_window::glfw::Context;
|
||||||
|
|
||||||
// adopted from the glium repo -> examples -> manual_creation.rs
|
// adopted from the glium repo -> examples -> manual_creation.rs
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct Backend {
|
pub struct Backend {
|
||||||
gl_window: Rc<RefCell<moonhare_window::glfw::Window>>,
|
pub gl_window: Rc<RefCell<moonhare_window::glfw::PWindow>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl glium::backend::Backend for Backend {
|
unsafe impl glium::backend::Backend for Backend {
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,32 @@
|
||||||
//! Crate for providing an abstraction layer over different graphics APIs
|
//! Crate for providing an abstraction layer over different graphics APIs
|
||||||
|
|
||||||
|
use std::{cell::RefCell, rc::Rc};
|
||||||
|
|
||||||
|
use glium::{backend::Context, Surface};
|
||||||
|
use moonhare_window::glfw::{PWindow, Window};
|
||||||
pub mod shader;
|
pub mod shader;
|
||||||
pub mod backend;
|
pub mod backend;
|
||||||
|
pub use glium;
|
||||||
|
|
||||||
|
|
||||||
|
pub fn build_context(window: PWindow) -> Rc<Context>{
|
||||||
|
let gl_window = Rc::new(RefCell::new(window));
|
||||||
|
// now building the context
|
||||||
|
|
||||||
|
let context = unsafe {
|
||||||
|
// The first parameter is our backend.
|
||||||
|
//
|
||||||
|
// The second parameter tells glium whether or not it should regularly call `is_current`
|
||||||
|
// on the backend to make sure that the OpenGL context is still the current one.
|
||||||
|
//
|
||||||
|
// It is recommended to pass `true`, but you can pass `false` if you are sure that no
|
||||||
|
// other OpenGL context will be made current in this thread.
|
||||||
|
let backend = backend::Backend {
|
||||||
|
gl_window: gl_window,
|
||||||
|
};
|
||||||
|
glium::backend::Context::new(backend, true, Default::default())
|
||||||
|
}
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
context
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use glfw::{Context, Glfw, GlfwReceiver, PWindow, WindowEvent};
|
use glfw::{Context, Glfw, GlfwReceiver, PWindow, Window, WindowEvent};
|
||||||
use moonhare_event::{event::Event, events::window_events::window_close_event::WindowCloseEvent};
|
use moonhare_event::{event::Event, events::window_events::window_close_event::WindowCloseEvent};
|
||||||
|
|
||||||
use crate::{window_config, MoonhareWindow};
|
use crate::{window_config, MoonhareWindow};
|
||||||
|
|
@ -30,7 +30,7 @@ impl GLFWWindow {
|
||||||
window.make_current();
|
window.make_current();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
glfw_window: window,
|
glfw_window: window.try_into().unwrap(),
|
||||||
events: events,
|
events: events,
|
||||||
glfw: glfw,
|
glfw: glfw,
|
||||||
is_running: true
|
is_running: true
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue