extern crate glium;
use glium::{Surface, glutin::{self, NotCurrent}, implement_vertex, uniform};
use std::vec;
#[derive(Clone, Copy)]
struct vertex{
position: [f32; 2]
}
const fragment_shader: &str = r#"
#version 140
out vec4 color;
void main(){
color = vec4(1.0, 0.0, 0.0, 0.0);
}
"#;
const vertex_shader: &str = r#"
#version 140
in vec2 position;
void main(){
gl_Position = vec4(position.x, position.y, 0.0, 1.0);
}
"#;
pub struct Graphics<'a, 'b>{
event_loop: glutin::event_loop::EventLoop<()>,
wb: glutin::window::WindowBuilder,
cb: glutin::ContextBuilder<'b, NotCurrent>,
display: glium::Display,
indices: glium::index::NoIndices,
program: glium::Program,
shape_holder: Vec<glium::VertexBuffer<vertex>>
}
impl<'a, 'b> Graphics<'a, 'b> {
pub fn new() -> Self{
implement_vertex!(vertex, position);
let event_loop = glutin::event_loop::EventLoop::new();
let wb = glutin::window::WindowBuilder::new();
let cb = glutin::ContextBuilder::new();
let display = glium::Display::new(wb, cb, &event_loop).unwrap();
let indices = glium::index::NoIndices(glium::index::PrimitiveType::TrianglesList);
let program = glium::Program::from_source(&display, vertex_shader, fragment_shader, None).unwrap();
Self{
event_loop,
wb,
cb,
display,
indices,
program,
shape_holder: Vec::new()
}
}
pub fn render(&mut self){
self.event_loop.run(move |ev, _, control_flow| {
let mut target = self.display.draw();
target.clear_color(0.0, 0.0, 1.0, 1.0);
//target.draw(&vertex_buffer,&indices, &program, &glium::uniforms::EmptyUniforms, &Default::default()).unwrap();
target.finish().unwrap();
let next_frame_time = std::time::Instant::now() +
std::time::Duration::from_nanos(16_666_667);
*control_flow = glutin::event_loop::ControlFlow::WaitUntil(next_frame_time);
match ev {
glutin::event::Event::WindowEvent { event, .. } => match event {
glutin::event::WindowEvent::CloseRequested => {
*control_flow = glutin::event_loop::ControlFlow::Exit;
return;
},
_ => return,
},
_ => (),
}
});
}
}
I am getting multiple problems due to lifetimes. Whenever i fix a problem, another (or more) problems will come out of nowhere.
i tried looking at multiple different solutions but none of them worked and caused more problems.
Also is concurrency and threading a good idea for my graphics script?
Can you guys help me fix all the bugs?