Pārlūkot izejas kodu

Add access to time

rexim 4 gadi atpakaļ
vecāks
revīzija
a843b51ce6
2 mainītis faili ar 10 papildinājumiem un 1 dzēšanām
  1. 3 0
      main.c
  2. 7 1
      main.frag

+ 3 - 0
main.c

@@ -109,6 +109,7 @@ bool link_program(GLuint vert_shader, GLuint frag_shader, GLuint *program)
 bool program_failed = false;
 GLuint program = 0;
 GLint resolution_location = 0;
+GLint time_location = 0;
 
 void reload_shaders(void)
 {
@@ -140,6 +141,7 @@ void reload_shaders(void)
     glUseProgram(program);
 
     resolution_location = glGetUniformLocation(program, "resolution");
+    time_location = glGetUniformLocation(program, "time");
 
     printf("Successfully Reload the Shaders\n");
 }
@@ -224,6 +226,7 @@ int main()
             glUniform2f(resolution_location,
                         SCREEN_WIDTH,
                         SCREEN_HEIGHT);
+            glUniform1f(time_location, glfwGetTime());
 
             glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
         }

+ 7 - 1
main.frag

@@ -1,9 +1,15 @@
 #version 130
 
 uniform vec2 resolution;
+uniform float time;
 
 out vec4 color;
 
 void main(void) {
-    color = vec4(gl_FragCoord.xy / resolution, 0.0, 1.0);
+    vec2 coord = gl_FragCoord.xy / resolution;
+    color = vec4(
+        (sin(coord.x + time) + 1.0) / 2.0,
+        (cos(coord.y + time) + 1.0) / 2.0,
+        (cos(coord.x + coord.y + time) + 1.0) / 2.0,
+        1.0);
 };