diff options
author | Kjetil Orbekk <kjetil.orbekk@gmail.com> | 2016-06-11 20:28:48 -0400 |
---|---|---|
committer | Kjetil Orbekk <kjetil.orbekk@gmail.com> | 2016-06-11 20:28:48 -0400 |
commit | d741d182a9bf475cb77b2f4599edae96f31e8541 (patch) | |
tree | 14a9e020e73625824616866cef4004b39a88d34e /rust/opengl/src/main.rs | |
parent | 0e65ca35e92f4f3a78467331eacd982cb9bcc50b (diff) |
OpenGL: Add uniform for translation.
Diffstat (limited to 'rust/opengl/src/main.rs')
-rw-r--r-- | rust/opengl/src/main.rs | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/rust/opengl/src/main.rs b/rust/opengl/src/main.rs index 667339b..ff24d1e 100644 --- a/rust/opengl/src/main.rs +++ b/rust/opengl/src/main.rs @@ -31,8 +31,11 @@ fn main() { let vertex_shader_src = r#" #version 140 in vec2 position; + uniform float t; void main() { - gl_Position = vec4(position, 0.0, 1.0); + vec2 p = position; + p.x += t; + gl_Position = vec4(p, 0.0, 1.0); } "#; @@ -40,16 +43,22 @@ fn main() { #version 140 out vec4 color; void main() { - color = vec4(1.0, 0.0, 0.0, 1.0); + color = vec4(0.7, 0.3, 0.2, 1.0); } "#; let program = glium::Program::from_source(&display, vertex_shader_src, fragment_shader_src, None).unwrap(); + let mut t: f32 = -0.5; loop { + t += 0.002; + if t > 0.5 { + t = -0.5; + } + let mut target = display.draw(); - target.clear_color(0.0, 0.0, 1.0, 1.0); - target.draw(&vertex_buffer, &indices, &program, &glium::uniforms::EmptyUniforms, + target.clear_color(0.3, 0.3, 0.2, 1.0); + target.draw(&vertex_buffer, &indices, &program, &uniform! { t: t }, &Default::default()).unwrap(); target.finish().unwrap(); |