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; | ||||
| 
 | ||||
| pub struct Game { | ||||
|     running: bool, | ||||
|     game_plugin: Option<Box<dyn GamePlugin>>, | ||||
|     window: Option<Window>, | ||||
|     display: Option<glium::Display<WindowSurface>>, | ||||
|     event_loop: EventLoop<()> | ||||
|     pub running: bool, | ||||
|     pub game_plugin: Option<Box<dyn GamePlugin>>, | ||||
|     pub window: Option<Window>, | ||||
|     pub display: Option<glium::Display<WindowSurface>>, | ||||
|     pub event_loop: EventLoop<()> | ||||
| } | ||||
| 
 | ||||
| impl Game { | ||||
|  | @ -31,7 +31,7 @@ impl Game { | |||
|         if let Some(ref mut game_plugin) = self.game_plugin { | ||||
|             game_plugin.init(); | ||||
|         } else { | ||||
|             todo!("Default Impl init") | ||||
|             //todo!("Default Impl init")
 | ||||
|         } | ||||
|         
 | ||||
|         let (_window, _display) = return_window(&self.event_loop); | ||||
|  | @ -43,7 +43,7 @@ impl Game { | |||
|         if let Some(ref mut game_plugin) = self.game_plugin { | ||||
|             game_plugin.update(); | ||||
|         } 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 { | ||||
|                 game_plugin.render(&mut target); | ||||
|             } 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 { | ||||
|             game_plugin.cleanup(); | ||||
|         } else { | ||||
|             todo!("Default Impl cleanup") | ||||
|             //todo!("Default Impl cleanup")
 | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  | @ -89,6 +89,7 @@ impl Game { | |||
|     } | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| impl ApplicationHandler for Game { | ||||
|     fn resumed(&mut self, event_loop: &event_loop::ActiveEventLoop) { | ||||
|         self.window = Some(event_loop.create_window(Window::default_attributes()).unwrap()) | ||||
|  | @ -120,6 +121,7 @@ impl ApplicationHandler for Game { | |||
| 
 | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| fn init_event_loop() -> EventLoop<()> { | ||||
|     let event_loop = glium::winit::event_loop::EventLoop::builder() | ||||
|         .build() | ||||
|  |  | |||
|  | @ -8,6 +8,14 @@ use glium::{glutin::surface::WindowSurface, uniform, uniforms, winit::{event::{s | |||
| 
 | ||||
| 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;
 | ||||
| // 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;
 | ||||
|  |  | |||
|  | @ -1,5 +1,6 @@ | |||
| use std::cell::RefCell; | ||||
| use std::fs::read_to_string; | ||||
| use std::ops::Deref; | ||||
| use std::rc::Rc; | ||||
| use std::sync::{Arc, Mutex}; | ||||
| 
 | ||||
|  | @ -26,7 +27,7 @@ impl GamePlugin for PlaygroundGame { | |||
| 
 | ||||
|     } | ||||
|     fn render(&mut self, target: &mut Frame) { | ||||
| 
 | ||||
|         
 | ||||
|         target.clear_color( | ||||
|             0.0, 
 | ||||
|             0.0, 
 | ||||
|  | @ -57,20 +58,23 @@ impl GamePlugin for PlaygroundGame { | |||
|             &uniforms, | ||||
|             &Default::default() | ||||
|         ).unwrap(); | ||||
| 
 | ||||
|         target.finish().unwrap(); | ||||
|     } | ||||
|     fn cleanup(&mut self) { | ||||
|         
 | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| fn main() { | ||||
| 
 | ||||
|     let game = RefCell::new(Game::new()); | ||||
|     let mut a = game.borrow_mut(); | ||||
|     a.init(); | ||||
| 
 | ||||
|     let binding = game.borrow(); | ||||
|     let g = binding.get_display(); | ||||
|     let binding = Some(a.display.clone()).unwrap().unwrap(); | ||||
|     // todo: unwraps on none
 | ||||
|     let g = binding; | ||||
| 
 | ||||
|     let shape = Vertex::define_shape( | ||||
|     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] } | ||||
|     ); | ||||
| 
 | ||||
| 
 | ||||
|     // "Upload" shape to the memory of the GPU (Vertex Buffer)
 | ||||
|     // 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
 | ||||
|  | @ -98,12 +103,12 @@ fn main() { | |||
|     // 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
 | ||||
| 
 | ||||
|     let vertex_shader_src = read_to_string("./shaders/vertex_shader.glsl").unwrap(); | ||||
|     let fragment_shader_src = read_to_string("./shaders/fragment_shader.glsl").unwrap(); | ||||
|     let vertex_shader_src = read_to_string("playground/src/shaders/vertex_shader.glsl").unwrap(); | ||||
|     let fragment_shader_src = read_to_string("playground/src/shaders/fragment_shader.glsl").unwrap(); | ||||
| 
 | ||||
|     // send shader source code to glium
 | ||||
|     let program = glium::Program::from_source( | ||||
|         g, 
 | ||||
|         &g, 
 | ||||
|         &vertex_shader_src, 
 | ||||
|         &fragment_shader_src, 
 | ||||
|         None | ||||
|  | @ -118,7 +123,7 @@ fn main() { | |||
|         program: program, | ||||
|     }; | ||||
| 
 | ||||
|     let mut a = game.borrow_mut(); | ||||
|     //let mut a = game.borrow_mut();
 | ||||
|     a.register_plugin(Box::new(pg_game)); | ||||
| 
 | ||||
|     a.run(); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue