summaryrefslogtreecommitdiff
path: root/rust
diff options
context:
space:
mode:
authorKjetil Orbekk <kjetil.orbekk@gmail.com>2016-06-11 21:57:14 -0400
committerKjetil Orbekk <kjetil.orbekk@gmail.com>2016-06-11 21:57:14 -0400
commitdd39f4c31641d3723df4b9a45cb8fef9538fca64 (patch)
treeba878b03de9a5cd3a22b47f70c16ae99c4510518 /rust
parentd741d182a9bf475cb77b2f4599edae96f31e8541 (diff)
Use matrix uniform.
Diffstat (limited to 'rust')
-rw-r--r--rust/opengl/src/main.rs20
1 files changed, 12 insertions, 8 deletions
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() {
}
}
}
-
}