window opens again but a lot of panicking D:
This commit is contained in:
		
					parent
					
						
							
								01ff7d39b1
							
						
					
				
			
			
				commit
				
					
						4b2d2a9dc4
					
				
			
		
					 3 changed files with 36 additions and 21 deletions
				
			
		|  | @ -5,11 +5,11 @@ use glium::{glutin::surface::WindowSurface, winit::{application::ApplicationHand | ||||||
| use crate::game_plugin::GamePlugin; | use crate::game_plugin::GamePlugin; | ||||||
| 
 | 
 | ||||||
| pub struct Game { | pub struct Game { | ||||||
|     running: bool, |     pub running: bool, | ||||||
|     game_plugin: Option<Box<dyn GamePlugin>>, |     pub game_plugin: Option<Box<dyn GamePlugin>>, | ||||||
|     window: Option<Window>, |     pub window: Option<Window>, | ||||||
|     display: Option<glium::Display<WindowSurface>>, |     pub display: Option<glium::Display<WindowSurface>>, | ||||||
|     event_loop: EventLoop<()> |     pub event_loop: EventLoop<()> | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl Game { | impl Game { | ||||||
|  | @ -31,7 +31,7 @@ impl Game { | ||||||
|         if let Some(ref mut game_plugin) = self.game_plugin { |         if let Some(ref mut game_plugin) = self.game_plugin { | ||||||
|             game_plugin.init(); |             game_plugin.init(); | ||||||
|         } else { |         } else { | ||||||
|             todo!("Default Impl init") |             //todo!("Default Impl init")
 | ||||||
|         } |         } | ||||||
|         
 |         
 | ||||||
|         let (_window, _display) = return_window(&self.event_loop); |         let (_window, _display) = return_window(&self.event_loop); | ||||||
|  | @ -43,7 +43,7 @@ impl Game { | ||||||
|         if let Some(ref mut game_plugin) = self.game_plugin { |         if let Some(ref mut game_plugin) = self.game_plugin { | ||||||
|             game_plugin.update(); |             game_plugin.update(); | ||||||
|         } else { |         } else { | ||||||
|             todo!("Default Impl update") |             //todo!("Default Impl update")
 | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -54,10 +54,10 @@ impl Game { | ||||||
|             if let Some(ref mut game_plugin) = self.game_plugin { |             if let Some(ref mut game_plugin) = self.game_plugin { | ||||||
|                 game_plugin.render(&mut target); |                 game_plugin.render(&mut target); | ||||||
|             } else { |             } else { | ||||||
|                 todo!("Default Impl render") |                 //todo!("Default Impl render")
 | ||||||
|             } |             } | ||||||
| 
 |             
 | ||||||
|             target.finish().unwrap(); |             let _ = &target.finish().unwrap(); | ||||||
|         }    
 |         }    
 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -65,7 +65,7 @@ impl Game { | ||||||
|         if let Some(ref mut game_plugin) = self.game_plugin { |         if let Some(ref mut game_plugin) = self.game_plugin { | ||||||
|             game_plugin.cleanup(); |             game_plugin.cleanup(); | ||||||
|         } else { |         } else { | ||||||
|             todo!("Default Impl cleanup") |             //todo!("Default Impl cleanup")
 | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -89,6 +89,7 @@ impl Game { | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| impl ApplicationHandler for Game { | impl ApplicationHandler for Game { | ||||||
|     fn resumed(&mut self, event_loop: &event_loop::ActiveEventLoop) { |     fn resumed(&mut self, event_loop: &event_loop::ActiveEventLoop) { | ||||||
|         self.window = Some(event_loop.create_window(Window::default_attributes()).unwrap()) |         self.window = Some(event_loop.create_window(Window::default_attributes()).unwrap()) | ||||||
|  | @ -120,6 +121,7 @@ impl ApplicationHandler for Game { | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| fn init_event_loop() -> EventLoop<()> { | fn init_event_loop() -> EventLoop<()> { | ||||||
|     let event_loop = glium::winit::event_loop::EventLoop::builder() |     let event_loop = glium::winit::event_loop::EventLoop::builder() | ||||||
|         .build() |         .build() | ||||||
|  |  | ||||||
|  | @ -8,6 +8,14 @@ use glium::{glutin::surface::WindowSurface, uniform, uniforms, winit::{event::{s | ||||||
| 
 | 
 | ||||||
| const ENGINE_NAME: &str = "Moonhare Engine"; | const ENGINE_NAME: &str = "Moonhare Engine"; | ||||||
| 
 | 
 | ||||||
|  | pub struct CPointer<T>(T); | ||||||
|  | 
 | ||||||
|  | impl<T> Drop for CPointer<T> { | ||||||
|  |     fn drop(&mut self) { | ||||||
|  |         println!("Dropping") | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| // rescaling:   position *= factor;
 | // rescaling:   position *= factor;
 | ||||||
| // rotating:    new_position = vec2(pos.x * cos(angle) - pos.y * sin(angle), pos.x * sin(single) + pos.y * cos(angle));
 | // rotating:    new_position = vec2(pos.x * cos(angle) - pos.y * sin(angle), pos.x * sin(single) + pos.y * cos(angle));
 | ||||||
| // skewing:     position.x += position.y * factor;
 | // skewing:     position.x += position.y * factor;
 | ||||||
|  |  | ||||||
|  | @ -1,5 +1,6 @@ | ||||||
| use std::cell::RefCell; | use std::cell::RefCell; | ||||||
| use std::fs::read_to_string; | use std::fs::read_to_string; | ||||||
|  | use std::ops::Deref; | ||||||
| use std::rc::Rc; | use std::rc::Rc; | ||||||
| use std::sync::{Arc, Mutex}; | use std::sync::{Arc, Mutex}; | ||||||
| 
 | 
 | ||||||
|  | @ -26,7 +27,7 @@ impl GamePlugin for PlaygroundGame { | ||||||
| 
 | 
 | ||||||
|     } |     } | ||||||
|     fn render(&mut self, target: &mut Frame) { |     fn render(&mut self, target: &mut Frame) { | ||||||
| 
 |         
 | ||||||
|         target.clear_color( |         target.clear_color( | ||||||
|             0.0, 
 |             0.0, 
 | ||||||
|             0.0, 
 |             0.0, 
 | ||||||
|  | @ -57,20 +58,23 @@ impl GamePlugin for PlaygroundGame { | ||||||
|             &uniforms, |             &uniforms, | ||||||
|             &Default::default() |             &Default::default() | ||||||
|         ).unwrap(); |         ).unwrap(); | ||||||
| 
 |  | ||||||
|         target.finish().unwrap(); |  | ||||||
|     } |     } | ||||||
|     fn cleanup(&mut self) { |     fn cleanup(&mut self) { | ||||||
|         
 |         
 | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| fn main() { | fn main() { | ||||||
| 
 | 
 | ||||||
|     let game = RefCell::new(Game::new()); |     let game = RefCell::new(Game::new()); | ||||||
|  |     let mut a = game.borrow_mut(); | ||||||
|  |     a.init(); | ||||||
| 
 | 
 | ||||||
|     let binding = game.borrow(); |     let binding = Some(a.display.clone()).unwrap().unwrap(); | ||||||
|     let g = binding.get_display(); |     // todo: unwraps on none
 | ||||||
|  |     let g = binding; | ||||||
| 
 | 
 | ||||||
|     let shape = Vertex::define_shape( |     let shape = Vertex::define_shape( | ||||||
|     Vertex { position: [-0.5, -0.5], color: [1.0, 0.0, 0.0] }, |     Vertex { position: [-0.5, -0.5], color: [1.0, 0.0, 0.0] }, | ||||||
|  | @ -78,10 +82,11 @@ fn main() { | ||||||
|     Vertex { position: [ 0.5, -0.25], color: [0.0, 0.0, 1.0] } |     Vertex { position: [ 0.5, -0.25], color: [0.0, 0.0, 1.0] } | ||||||
|     ); |     ); | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|     // "Upload" shape to the memory of the GPU (Vertex Buffer)
 |     // "Upload" shape to the memory of the GPU (Vertex Buffer)
 | ||||||
|     // Isn't strictly necessary but, makes tge drawing operation faster
 |     // Isn't strictly necessary but, makes tge drawing operation faster
 | ||||||
|     
 |     
 | ||||||
|     let vertex_buffer: VertexBuffer<Vertex> = VertexBuffer::new(g, &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
 |     // Complex shapes consist of hundreds/thousands of vertices -> need to have a list of vertices and tell OpenGL how to link these
 | ||||||
|  | @ -98,12 +103,12 @@ fn main() { | ||||||
|     // Important to write matrix * vertex -> Matrix operations produce different results depending on the order
 |     // Important to write matrix * vertex -> Matrix operations produce different results depending on the order
 | ||||||
|     // out: defines a variable that is going to be passed along to the fragment shader
 |     // out: defines a variable that is going to be passed along to the fragment shader
 | ||||||
| 
 | 
 | ||||||
|     let vertex_shader_src = read_to_string("./shaders/vertex_shader.glsl").unwrap(); |     let vertex_shader_src = read_to_string("playground/src/shaders/vertex_shader.glsl").unwrap(); | ||||||
|     let fragment_shader_src = read_to_string("./shaders/fragment_shader.glsl").unwrap(); |     let fragment_shader_src = read_to_string("playground/src/shaders/fragment_shader.glsl").unwrap(); | ||||||
| 
 | 
 | ||||||
|     // send shader source code to glium
 |     // send shader source code to glium
 | ||||||
|     let program = glium::Program::from_source( |     let program = glium::Program::from_source( | ||||||
|         g, 
 |         &g, 
 | ||||||
|         &vertex_shader_src, 
 |         &vertex_shader_src, 
 | ||||||
|         &fragment_shader_src, 
 |         &fragment_shader_src, 
 | ||||||
|         None |         None | ||||||
|  | @ -118,7 +123,7 @@ fn main() { | ||||||
|         program: program, |         program: program, | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     let mut a = game.borrow_mut(); |     //let mut a = game.borrow_mut();
 | ||||||
|     a.register_plugin(Box::new(pg_game)); |     a.register_plugin(Box::new(pg_game)); | ||||||
| 
 | 
 | ||||||
|     a.run(); |     a.run(); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue