I'm just getting started with Rust and Glium.
I tried to render some triangles to the screen. I'm getting 8 FPS, and I'm only rendering 8192 triangles. What am I doing wrong?
This is my source code:
#[macro_use]
extern crate glium;
use glium::{glutin, Surface};
#[derive(Copy,Clone)]
struct Vertex {
position: [f32; 2],
color: [f32; 3],
}
implement_vertex!(Vertex,position,color);
extern crate rand;
extern crate time;
fn main() {
let mut events_loop = glutin::EventsLoop::new();
let window = glutin::WindowBuilder::new().with_fullscreen(glium::glutin::get_primary_monitor());
let context = glutin::ContextBuilder::new();
let display = glium::Display::new(window, context, &events_loop).unwrap();
let mut shape = Vec::new();
for _ in 0..24576 {
shape.push(Vertex{
position: [rand::random::<f32>(),rand::random::<f32>()],
color: [rand::random::<f32>(),rand::random::<f32>(),rand::random::<f32>()]
});
}
let vertex_shader_src = r#"
#version 140
in vec2 position;
in vec3 color;
out vec3 v_color;
void main() {
v_color = color;
gl_Position = vec4(position, 0.0, 1.0);
}
"#;
let fragment_shader_src = r#"
#version 140
in vec3 v_color;
out vec4 color;
void main() {
color = vec4(v_color, 1.0);
}
"#;
let vertex_buffer = glium::VertexBuffer::new(&display, &shape).unwrap();
let indices = glium::index::NoIndices(glium::index::PrimitiveType::TrianglesList);
let program = glium::Program::from_source(&display, vertex_shader_src, fragment_shader_src, None).unwrap();
let mut begin_stamp = time::precise_time_ns();
let mut running = true;
let mut count: u64 = 0;
while running {
count += 1;
let mut target = display.draw();
target.clear_color(0.0, 0.0, 0.5, 1.0);
target.draw(&vertex_buffer, &indices, &program, &glium::uniforms::EmptyUniforms,
&Default::default()).unwrap();
target.finish().unwrap();
events_loop.poll_events(|event| {
match event {
glutin::Event::WindowEvent { event, .. } => match event {
glutin::WindowEvent::Closed => running = false,
_ => ()
},
_ => (),
}
});
// if (time::precise_time_ns()-last_print) > 1000000000 {
// last_print = time::precise_time_ns();
// println!("Loop time is {} ns", time::precise_time_ns()-last_loop);
// }
// last_loop = time::precise_time_ns();
}
println!("Loop ran {} times",count);
println!("Total elapsed ns: {}",time::precise_time_ns()-begin_stamp);
}
Any help is very much appreciated.
I'm also new to the forum, so any advice concerning forum etiquette would also be great.
Thanks!