From dd39f4c31641d3723df4b9a45cb8fef9538fca64 Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Sat, 11 Jun 2016 21:57:14 -0400 Subject: Use matrix uniform. --- rust/opengl/src/main.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'rust/opengl') diff --git a/rust/opengl/src/main.rs b/rust/opengl/src/main.rs index ff24d1e..d7b3a52 100644 --- a/rust/opengl/src/main.rs +++ b/rust/opengl/src/main.rs @@ -11,8 +11,6 @@ fn main() { .build_glium() .unwrap(); - // let display = glium::glutin::WindowBuilder::new().build_glium().unwrap(); - #[derive(Copy, Clone)] struct Vertex { position: [f32; 2], @@ -31,11 +29,9 @@ fn main() { let vertex_shader_src = r#" #version 140 in vec2 position; - uniform float t; + uniform mat4 trans; void main() { - vec2 p = position; - p.x += t; - gl_Position = vec4(p, 0.0, 1.0); + gl_Position = trans * vec4(position, 0.0, 1.0); } "#; @@ -56,9 +52,18 @@ fn main() { t = -0.5; } + let uniforms = uniform! { + trans: [ + [t.cos(), t.sin(), 0.0, 0.0], + [-t.sin(), t.cos(), 0.0, 0.0], + [1.0, 0.0, 1.0, 0.0], + [t, 0.0, 0.0, 1.0f32], + ] + }; + let mut target = display.draw(); target.clear_color(0.3, 0.3, 0.2, 1.0); - target.draw(&vertex_buffer, &indices, &program, &uniform! { t: t }, + target.draw(&vertex_buffer, &indices, &program, &uniforms, &Default::default()).unwrap(); target.finish().unwrap(); @@ -69,5 +74,4 @@ fn main() { } } } - } -- cgit v1.2.3