stuff oder so
This commit is contained in:
parent
78b5348b92
commit
0eeb4b2563
8 changed files with 286 additions and 18 deletions
210
Cargo.lock
generated
210
Cargo.lock
generated
|
|
@ -46,6 +46,15 @@ dependencies = [
|
|||
"zerocopy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "android-activity"
|
||||
version = "0.6.0"
|
||||
|
|
@ -696,6 +705,19 @@ dependencies = [
|
|||
"pin-project-lite",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "generator"
|
||||
version = "0.7.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5cc16584ff22b460a382b7feec54b23d2908d858152e5739a120b949293bd74e"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
"log",
|
||||
"rustversion",
|
||||
"windows",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gethostname"
|
||||
version = "0.4.3"
|
||||
|
|
@ -901,6 +923,12 @@ dependencies = [
|
|||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
|
||||
|
||||
[[package]]
|
||||
name = "jni"
|
||||
version = "0.21.1"
|
||||
|
|
@ -1010,6 +1038,30 @@ version = "0.4.27"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
|
||||
|
||||
[[package]]
|
||||
name = "loom"
|
||||
version = "0.5.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ff50ecb28bb86013e935fb6683ab1f6d3a20016f123c76fd4c27470076ac30f5"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"generator",
|
||||
"scoped-tls",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "matchers"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558"
|
||||
dependencies = [
|
||||
"regex-automata 0.1.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.7.5"
|
||||
|
|
@ -1068,7 +1120,9 @@ name = "moonhare_graphics"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"glium",
|
||||
"lazy_static",
|
||||
"moonhare_window",
|
||||
"state",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -1137,6 +1191,16 @@ version = "0.5.5"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "610a5acd306ec67f907abe5567859a3c693fb9886eb1f012ab8f2a47bef3db51"
|
||||
|
||||
[[package]]
|
||||
name = "nu-ansi-term"
|
||||
version = "0.46.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
|
||||
dependencies = [
|
||||
"overload",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_enum"
|
||||
version = "0.7.4"
|
||||
|
|
@ -1429,6 +1493,12 @@ dependencies = [
|
|||
"libredox",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "overload"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
|
||||
|
||||
[[package]]
|
||||
name = "owned_ttf_parser"
|
||||
version = "0.25.1"
|
||||
|
|
@ -1607,6 +1677,50 @@ dependencies = [
|
|||
"bitflags 2.9.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-automata 0.4.9",
|
||||
"regex-syntax 0.8.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
|
||||
dependencies = [
|
||||
"regex-syntax 0.6.29",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax 0.8.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.6.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
|
||||
|
||||
[[package]]
|
||||
name = "rustc-demangle"
|
||||
version = "0.1.26"
|
||||
|
|
@ -1645,6 +1759,12 @@ version = "1.0.21"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a0d197bd2c9dc6e53b84da9556a69ba4cdfab8619eb41a8bd1cc2027a0f6b1d"
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
|
||||
|
||||
[[package]]
|
||||
name = "same-file"
|
||||
version = "1.0.6"
|
||||
|
|
@ -1699,6 +1819,27 @@ dependencies = [
|
|||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.142"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "030fedb782600dcbd6f02d479bf0d817ac3bb40d644745b769d6a96bc3afc5a7"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"memchr",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sharded-slab"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "1.3.0"
|
||||
|
|
@ -1766,6 +1907,15 @@ version = "1.2.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
|
||||
|
||||
[[package]]
|
||||
name = "state"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b8c4a4445d81357df8b1a650d0d0d6fbbbfe99d064aa5e02f3e4022061476d8"
|
||||
dependencies = [
|
||||
"loom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strict-num"
|
||||
version = "0.1.1"
|
||||
|
|
@ -1881,14 +2031,59 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0"
|
||||
dependencies = [
|
||||
"pin-project-lite",
|
||||
"tracing-attributes",
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-attributes"
|
||||
version = "0.1.30"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "81383ab64e72a7a8b8e13130c49e3dab29def6d0c7d76a03087b3cf71c5c6903"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-core"
|
||||
version = "0.1.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9d12581f227e93f094d3af2ae690a574abb8a2b9b7a96e7cfe9647b2b617678"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"valuable",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-log"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3"
|
||||
dependencies = [
|
||||
"log",
|
||||
"once_cell",
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-subscriber"
|
||||
version = "0.3.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008"
|
||||
dependencies = [
|
||||
"matchers",
|
||||
"nu-ansi-term",
|
||||
"once_cell",
|
||||
"regex",
|
||||
"sharded-slab",
|
||||
"smallvec",
|
||||
"thread_local",
|
||||
"tracing",
|
||||
"tracing-core",
|
||||
"tracing-log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ttf-parser"
|
||||
|
|
@ -1932,6 +2127,12 @@ dependencies = [
|
|||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "valuable"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65"
|
||||
|
||||
[[package]]
|
||||
name = "variadics_please"
|
||||
version = "1.1.0"
|
||||
|
|
@ -2212,6 +2413,15 @@ version = "0.4.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "windows"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f"
|
||||
dependencies = [
|
||||
"windows-targets 0.48.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-link"
|
||||
version = "0.1.3"
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
//! Base functionality for a Moonhare Game Engine Project
|
||||
|
||||
use std::{cell::{RefCell, RefMut}, rc::Rc, sync::Arc};
|
||||
use std::rc::Rc;
|
||||
|
||||
use moonhare_graphics::glium::{backend::Context, glutin::api::egl::context, winit::event_loop};
|
||||
use moonhare_graphics::{color::Color, glium::{backend::Context, glutin::api::egl::context}};
|
||||
use moonhare_log::*;
|
||||
use moonhare_window::{glfw::PWindow, platforms::glfw_window::GLFWWindow};
|
||||
use moonhare_window::{platforms::glfw_window::GLFWWindow};
|
||||
pub mod basic;
|
||||
|
||||
/// Only one Game may exist per project
|
||||
|
|
@ -13,7 +13,7 @@ pub struct Game {
|
|||
pub is_running: bool,
|
||||
pub name: String,
|
||||
pub context: moonhare_window::WindowRenderContext,
|
||||
pub glfw_window: Option<moonhare_window::platforms::glfw_window::GLFWWindow>
|
||||
pub glfw_window: Option<moonhare_window::platforms::glfw_window::GLFWWindow>,
|
||||
}
|
||||
|
||||
impl Default for Game {
|
||||
|
|
@ -27,6 +27,16 @@ impl Default for Game {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct GraphicsHandler {
|
||||
pub context: Option<Rc<Context>>
|
||||
}
|
||||
|
||||
impl Default for GraphicsHandler {
|
||||
fn default() -> Self {
|
||||
Self { context: None }
|
||||
}
|
||||
}
|
||||
|
||||
impl Game {
|
||||
pub fn new() -> Self {
|
||||
Game::default()
|
||||
|
|
@ -34,15 +44,15 @@ impl Game {
|
|||
|
||||
pub fn run(self) {
|
||||
info("Running Game...");
|
||||
let mut glfw_window_unwrapped = self.glfw_window;
|
||||
let mut context: std::rc::Rc<moonhare_graphics::glium::backend::Context>;
|
||||
let glfw_window_unwrapped = self.glfw_window;
|
||||
let mut graphics_handler: GraphicsHandler = GraphicsHandler { ..Default::default() };
|
||||
let context: std::rc::Rc<moonhare_graphics::glium::backend::Context>;
|
||||
|
||||
context = moonhare_graphics::build_context(glfw_window_unwrapped.clone().unwrap().glfw_window);
|
||||
|
||||
|
||||
graphics_handler.context = Some(context.clone());
|
||||
let mut value = glfw_window_unwrapped;
|
||||
while self.is_running {
|
||||
// can't move glfwwindow cause i can't implement clone, or idk
|
||||
handle_window_event(value.as_mut().unwrap());
|
||||
render(context.clone());
|
||||
|
||||
|
|
@ -61,7 +71,7 @@ fn default_game_name() -> String {
|
|||
}
|
||||
|
||||
/// Deals with GLFW Window Events (in `monhare_window`)
|
||||
fn handle_window_event(mut glfw_window: &GLFWWindow) {
|
||||
fn handle_window_event(glfw_window: &GLFWWindow) {
|
||||
glfw_window.glfw_window.borrow_mut().glfw.poll_events();
|
||||
for (_, event) in moonhare_window::glfw::flush_messages(&glfw_window.events.borrow()) {
|
||||
moonhare_window::platforms::glfw_window::GLFWWindow::handle_window_event(&glfw_window, event);
|
||||
|
|
@ -69,8 +79,6 @@ fn handle_window_event(mut glfw_window: &GLFWWindow) {
|
|||
}
|
||||
|
||||
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();
|
||||
let target = moonhare_graphics::glium::Frame::new(context.clone(), context.get_framebuffer_dimensions());
|
||||
moonhare_graphics::draw_background_color(Color::color_from_rgb(255, 255, 255), target);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,3 +7,5 @@ authors.workspace = true
|
|||
[dependencies]
|
||||
moonhare_window = { path = "../moonhare_window" }
|
||||
glium = "0.36"
|
||||
state = "0.6"
|
||||
lazy_static = "*"
|
||||
29
crates/moonhare_graphics/src/color.rs
Normal file
29
crates/moonhare_graphics/src/color.rs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
pub struct Color {
|
||||
pub red: f32,
|
||||
pub green: f32,
|
||||
pub blue: f32,
|
||||
pub alpha: f32
|
||||
}
|
||||
|
||||
impl Color {
|
||||
/// Color Values from 0 - 255
|
||||
/// For example: 255, 255, 255 -> White
|
||||
pub fn color_from_rgb(red: i32, green: i32, blue: i32) -> Self {
|
||||
// 255 -> 1.0
|
||||
// 0 -> 0.0
|
||||
let r: f32 = red as f32/ 255.0;
|
||||
let g: f32 = green as f32 / 255.0;
|
||||
let b: f32 = blue as f32/ 255.0;
|
||||
Self { red: r, green: g, blue: b, alpha: 1.0 }
|
||||
}
|
||||
|
||||
pub fn color_from_rgba(red: i32, green: i32, blue: i32, alpha: f32) -> Self {
|
||||
// 255 -> 1.0
|
||||
// 0 -> 0.0
|
||||
let r: f32 = red as f32 / 255.0;
|
||||
let g: f32 = green as f32 / 255.0;
|
||||
let b: f32 = blue as f32 / 255.0;
|
||||
let a: f32 = alpha;
|
||||
Self { red: r, green: g, blue: b, alpha: a }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +1,21 @@
|
|||
//! Crate for providing an abstraction layer over different graphics APIs
|
||||
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
use std::{cell::{Cell, RefCell}, rc::Rc, sync::{Arc, Mutex, RwLock}};
|
||||
|
||||
use glium::{backend::Context, Surface};
|
||||
use moonhare_window::glfw::{PWindow, Window};
|
||||
use glium::{backend::{Context, Facade}, Frame, Surface};
|
||||
use lazy_static::lazy_static;
|
||||
use moonhare_window::glfw::PWindow;
|
||||
pub mod shader;
|
||||
pub mod backend;
|
||||
pub mod vertices;
|
||||
pub mod color;
|
||||
pub use glium;
|
||||
use state::InitCell;
|
||||
|
||||
use crate::color::Color;
|
||||
|
||||
pub fn build_context(window: Rc<RefCell<PWindow>>) -> Rc<Context>{
|
||||
let gl_window = window;
|
||||
let gl_window: Rc<RefCell<PWindow>> = window;
|
||||
// now building the context
|
||||
|
||||
let context = unsafe {
|
||||
|
|
@ -27,6 +32,10 @@ pub fn build_context(window: Rc<RefCell<PWindow>>) -> Rc<Context>{
|
|||
glium::backend::Context::new(backend, true, Default::default())
|
||||
}
|
||||
.unwrap();
|
||||
|
||||
context
|
||||
}
|
||||
|
||||
pub fn draw_background_color(color: Color, mut target: Frame) {
|
||||
Surface::clear_color(&mut target, color.red, color.green, color.blue, color.alpha);
|
||||
target.finish().unwrap()
|
||||
}
|
||||
1
crates/moonhare_graphics/src/vertices/mod.rs
Normal file
1
crates/moonhare_graphics/src/vertices/mod.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
pub mod vertex;
|
||||
8
crates/moonhare_graphics/src/vertices/vertex.rs
Normal file
8
crates/moonhare_graphics/src/vertices/vertex.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
use glium::implement_vertex;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct Vertex {
|
||||
pub(crate) position: [f32; 2],
|
||||
pub(crate) color: [f32; 3],
|
||||
}
|
||||
implement_vertex!(Vertex, position, color);
|
||||
|
|
@ -7,6 +7,7 @@ use crate::{window_config, MoonhareWindow};
|
|||
|
||||
#[derive(Debug)]
|
||||
pub struct GLFWWindow {
|
||||
// Todo: learn more about rust smart pointers so i actually understand whats going on here, but hey it works for now
|
||||
pub glfw_window: Rc<RefCell<PWindow>>,
|
||||
pub events: Rc<RefCell<GlfwReceiver<(f64, WindowEvent)>>>,
|
||||
pub glfw: Glfw,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue