GLM stuff
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
#version 330
|
||||
|
||||
in vec2 position;
|
||||
in vec3 position;
|
||||
in vec3 color;
|
||||
|
||||
uniform mat4 MVP;
|
||||
|
||||
out vec3 DIFFUSE;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(position, 0.0, 1.0);
|
||||
gl_Position = MVP * vec4(position, 1.0);
|
||||
DIFFUSE = color;
|
||||
}
|
||||
|
||||
21
src/main.rs
21
src/main.rs
@@ -1,9 +1,10 @@
|
||||
#[macro_use]
|
||||
extern crate glium;
|
||||
extern crate nalgebra_glm as glm;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
struct Vertex {
|
||||
position: [f32; 2],
|
||||
position: [f32; 3],
|
||||
color: [f32; 3],
|
||||
}
|
||||
|
||||
@@ -19,9 +20,9 @@ fn main() {
|
||||
|
||||
let display = glium::Display::new(wb, cb, &events_loop).unwrap();
|
||||
|
||||
let vertex1 = Vertex { position: [-0.5, -0.5], color: [1.0, 0.0, 0.0] };
|
||||
let vertex2 = Vertex { position: [ 0.0, 0.5], color: [0.0, 1.0, 0.0] };
|
||||
let vertex3 = Vertex { position: [ 0.5, -0.25], color: [0.0, 0.0, 1.0]};
|
||||
let vertex1 = Vertex { position: [-0.5, -0.5, 0.0], color: [1.0, 0.0, 0.0] };
|
||||
let vertex2 = Vertex { position: [ 0.0, 0.5, 0.0], color: [0.0, 1.0, 0.0] };
|
||||
let vertex3 = Vertex { position: [ 0.5, -0.25, 0.0], color: [0.0, 0.0, 1.0]};
|
||||
let shape = vec![vertex1, vertex2, vertex3];
|
||||
|
||||
let vertex_buffer = glium::VertexBuffer::new(&display, &shape).unwrap();
|
||||
@@ -31,11 +32,21 @@ fn main() {
|
||||
let fragment_shader_src = include_str!("flat.frag");
|
||||
let program = glium::Program::from_source(&display, vertex_shader_src, fragment_shader_src, None).unwrap();
|
||||
|
||||
let mut frames = 0;
|
||||
|
||||
events_loop.run(move |ev, _, control_flow| {
|
||||
|
||||
frames += 1;
|
||||
|
||||
let mvp = glm::perspective::<f32>(1.0, 45.0_f32.to_radians(), 0.2, 100.0);
|
||||
let mvp = glm::translate::<f32>(&mvp, &glm::vec3(0.0, 0.0, -10.0 + frames as f32 * 0.01));
|
||||
let uniforms = uniform! {
|
||||
MVP: *mvp.as_ref(),
|
||||
};
|
||||
|
||||
let mut target = display.draw();
|
||||
target.clear_color(0.0, 0.0, 0.0, 1.0);
|
||||
target.draw(&vertex_buffer, &indices, &program, &glium::uniforms::EmptyUniforms,
|
||||
target.draw(&vertex_buffer, &indices, &program, &uniforms,
|
||||
&Default::default()).unwrap();
|
||||
target.finish().unwrap();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user