mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-12 18:38:43 -06:00
got a window
This commit is contained in:
parent
fcb123b02f
commit
d77779d720
59
src/main.rs
59
src/main.rs
|
@ -1,16 +1,63 @@
|
||||||
use glium::glutin::event_loop::EventLoop;
|
use shipyard::{World, Workload, IntoWorkload, View, UniqueView, NonSendSync};
|
||||||
use shipyard::World;
|
use glium::{
|
||||||
|
Surface,
|
||||||
|
glutin::{
|
||||||
|
event_loop::{EventLoop, ControlFlow},
|
||||||
|
event::{Event, WindowEvent}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
mod logging;
|
mod logging;
|
||||||
|
mod rendering;
|
||||||
|
|
||||||
|
use rendering::{Rederer, RenderTarget};
|
||||||
|
|
||||||
|
fn render() -> Workload {
|
||||||
|
(||()).into_workload()
|
||||||
|
}
|
||||||
|
fn update() -> Workload {
|
||||||
|
(||()).into_workload()
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
logging::init();
|
logging::init();
|
||||||
|
|
||||||
let world = World::new();
|
|
||||||
world.add_unique(component)
|
|
||||||
|
|
||||||
|
//Create event loop
|
||||||
let event_loop = EventLoop::new();
|
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| {
|
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();
|
||||||
|
},
|
||||||
|
_ => (),
|
||||||
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue