From d741d182a9bf475cb77b2f4599edae96f31e8541 Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Sat, 11 Jun 2016 20:28:48 -0400 Subject: OpenGL: Add uniform for translation. --- rust/opengl/src/main.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'rust/opengl/src/main.rs') 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(); -- cgit v1.2.3