diff options
author | lonkaars <loek@pipeframe.xyz> | 2024-05-16 20:18:59 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2024-05-16 20:18:59 +0200 |
commit | 8d7911dc40c3bfc8f4fae65f29f4c8094aec79f7 (patch) | |
tree | e3ded763bc15661cfa7cf420e5e96643eb865722 /main.c | |
parent | 68081ef4f1f51b5753e25a1be6f870eb2e84f76e (diff) |
add uniform variable to shader
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -1,6 +1,8 @@ #include <stdlib.h> #include <GL/glew.h> #include <GLFW/glfw3.h> +#include <sys/time.h> +#include <time.h> #include "shader.h" #include "die.h" @@ -63,10 +65,21 @@ int main(int argc, char** argv) { frag_shader(visuals_frag, visuals_frag_size) ); + // prepare uniform variables + GLint u_time = glGetUniformLocation(shader, "time"); + int time_start = time(NULL); + // main draw loop while (!glfwWindowShouldClose(window)) { glfwPollEvents(); + // set `time` uniform + struct timeval t; + gettimeofday(&t, NULL); + t.tv_sec -= time_start; + float time = t.tv_sec + (t.tv_usec / 1e6); + glUniform1f(u_time, time); + glUseProgram(shader); glDrawArrays(GL_TRIANGLES, 0, 3); |