fn main in playground has no errors currently
This commit is contained in:
parent
552a36a146
commit
01ff7d39b1
3 changed files with 29 additions and 11 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use glium::{glutin::surface::WindowSurface, winit::{application::ApplicationHandler, event::{Event, WindowEvent}, event_loop::{self, EventLoop}, window::{self, Window}}, Display};
|
||||
use glium::{glutin::surface::WindowSurface, winit::{application::ApplicationHandler, event::{Event, WindowEvent}, event_loop::{self, EventLoop}, window::{self, Window, WindowAttributes}}, Display};
|
||||
|
||||
use crate::game_plugin::GamePlugin;
|
||||
|
||||
|
|
@ -8,7 +8,7 @@ pub struct Game {
|
|||
running: bool,
|
||||
game_plugin: Option<Box<dyn GamePlugin>>,
|
||||
window: Option<Window>,
|
||||
display: Arc<Mutex<Option<glium::Display<WindowSurface>>>>,
|
||||
display: Option<glium::Display<WindowSurface>>,
|
||||
event_loop: EventLoop<()>
|
||||
}
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ impl Game {
|
|||
running: true,
|
||||
game_plugin: None,
|
||||
window: None,
|
||||
display: Arc::new(Mutex::new(None)),
|
||||
display: None,
|
||||
event_loop: init_event_loop(),
|
||||
}
|
||||
}
|
||||
|
|
@ -36,7 +36,7 @@ impl Game {
|
|||
|
||||
let (_window, _display) = return_window(&self.event_loop);
|
||||
self.window = Some(_window);
|
||||
self.display = Arc::new(Mutex::new(Some(_display)));
|
||||
self.display = Some(_display);
|
||||
}
|
||||
|
||||
pub fn update(&mut self) {
|
||||
|
|
@ -48,7 +48,7 @@ impl Game {
|
|||
}
|
||||
|
||||
pub fn render(&mut self) {
|
||||
if let Some(ref display) = self.display.into() {
|
||||
if let Some(ref display) = self.display{
|
||||
let mut target = display.draw();
|
||||
|
||||
if let Some(ref mut game_plugin) = self.game_plugin {
|
||||
|
|
@ -79,6 +79,14 @@ impl Game {
|
|||
|
||||
self.cleanup();
|
||||
}
|
||||
|
||||
pub fn get_display(&self) -> &glium::Display<WindowSurface>{
|
||||
self.display.as_ref().unwrap()
|
||||
}
|
||||
|
||||
pub fn get_window(self) -> Option<Window> {
|
||||
return self.window;
|
||||
}
|
||||
}
|
||||
|
||||
impl ApplicationHandler for Game {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use glium::Frame;
|
||||
|
||||
|
||||
pub trait GamePlugin {
|
||||
fn init(&mut self);
|
||||
fn update(&mut self);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
use std::cell::RefCell;
|
||||
use std::fs::read_to_string;
|
||||
use std::rc::Rc;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use glium::glutin::surface::WindowSurface;
|
||||
use glium::{index::NoIndices, Frame, Program, VertexBuffer};
|
||||
use glium::{program, uniform, Display, Surface};
|
||||
use moonhare_engine::{game::Game, game_plugin::GamePlugin, vertex::Vertex};
|
||||
|
|
@ -63,7 +67,10 @@ impl GamePlugin for PlaygroundGame {
|
|||
|
||||
fn main() {
|
||||
|
||||
let mut game: Game = Game::new();
|
||||
let game = RefCell::new(Game::new());
|
||||
|
||||
let binding = game.borrow();
|
||||
let g = binding.get_display();
|
||||
|
||||
let shape = Vertex::define_shape(
|
||||
Vertex { position: [-0.5, -0.5], color: [1.0, 0.0, 0.0] },
|
||||
|
|
@ -73,7 +80,8 @@ fn main() {
|
|||
|
||||
// "Upload" shape to the memory of the GPU (Vertex Buffer)
|
||||
// Isn't strictly necessary but, makes tge drawing operation faster
|
||||
let vertex_buffer = glium::VertexBuffer::new(&display, &shape).unwrap();
|
||||
|
||||
let vertex_buffer: VertexBuffer<Vertex> = VertexBuffer::new(g, &shape).unwrap();
|
||||
|
||||
|
||||
// Complex shapes consist of hundreds/thousands of vertices -> need to have a list of vertices and tell OpenGL how to link these
|
||||
|
|
@ -95,14 +103,14 @@ fn main() {
|
|||
|
||||
// send shader source code to glium
|
||||
let program = glium::Program::from_source(
|
||||
glium::Display::new(context, surface),
|
||||
g,
|
||||
&vertex_shader_src,
|
||||
&fragment_shader_src,
|
||||
None
|
||||
).unwrap();
|
||||
|
||||
|
||||
let mut pg_game = PlaygroundGame {
|
||||
let pg_game = PlaygroundGame {
|
||||
t: 0.0,
|
||||
shape: shape,
|
||||
vertex_buffer: vertex_buffer,
|
||||
|
|
@ -110,7 +118,8 @@ fn main() {
|
|||
program: program,
|
||||
};
|
||||
|
||||
game.register_plugin(Box::new(pg_game));
|
||||
let mut a = game.borrow_mut();
|
||||
a.register_plugin(Box::new(pg_game));
|
||||
|
||||
game.run();
|
||||
a.run();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue