stuff oder so

This commit is contained in:
LunarAkai 2025-08-03 23:27:32 +02:00
commit 0eeb4b2563
8 changed files with 286 additions and 18 deletions

View file

@ -7,3 +7,5 @@ authors.workspace = true
[dependencies]
moonhare_window = { path = "../moonhare_window" }
glium = "0.36"
state = "0.6"
lazy_static = "*"

View 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 }
}
}

View file

@ -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()
}

View file

@ -0,0 +1 @@
pub mod vertex;

View 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);