got a window

This commit is contained in:
griffi-gh 2023-01-19 23:28:07 +01:00
parent fcb123b02f
commit d77779d720
2 changed files with 83 additions and 8 deletions

View file

@ -1,16 +1,63 @@
use glium::glutin::event_loop::EventLoop;
use shipyard::World;
use shipyard::{World, Workload, IntoWorkload, View, UniqueView, NonSendSync};
use glium::{
Surface,
glutin::{
event_loop::{EventLoop, ControlFlow},
event::{Event, WindowEvent}
}
};
mod logging;
mod rendering;
use rendering::{Rederer, RenderTarget};
fn render() -> Workload {
(||()).into_workload()
}
fn update() -> Workload {
(||()).into_workload()
}
fn main() {
logging::init();
let world = World::new();
world.add_unique(component)
//Create event loop
let event_loop = EventLoop::new();
//Create a shipyard world
let world = World::new();
//Add systems and uniques
world.add_unique_non_send_sync(
Rederer::init(&event_loop)
);
world.add_workload(update);
world.add_workload(render);
//Run the event loop
event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Poll;
match event {
Event::WindowEvent { event, .. } => match event {
WindowEvent::CloseRequested => {
*control_flow = ControlFlow::Exit;
},
_ => (),
},
Event::MainEventsCleared => {
world.run_workload(update).unwrap();
let mut target = {
let renderer = world.borrow::<NonSendSync<UniqueView<Rederer>>>().unwrap();
renderer.display.draw()
};
target.clear_color_and_depth((0., 0., 0., 1.), 1.);
world.add_unique_non_send_sync(RenderTarget(target));
world.run_workload(render).unwrap();
let target = world.remove_unique::<RenderTarget>().unwrap();
target.0.finish().unwrap();
},
_ => (),
};
});
}

View file

@ -1,3 +1,31 @@
fn init_display() {
use shipyard::Unique;
use glium::{
glutin::{
event_loop::EventLoop,
window::WindowBuilder,
ContextBuilder, GlProfile
},
Display,
};
#[derive(Unique)]
pub struct RenderTarget(pub glium::Frame);
#[derive(Unique)]
pub struct Rederer {
pub display: Display
}
impl Rederer {
pub fn init(event_loop: &EventLoop<()>) -> Self {
log::info!("initializing display");
let wb = WindowBuilder::new()
.with_title("uwu")
.with_maximized(true);
let cb = ContextBuilder::new()
.with_depth_buffer(24)
.with_gl_profile(GlProfile::Core);
let display = Display::new(wb, cb, event_loop)
.expect("Failed to create a glium Display");
Self { display }
}
}