aboutsummaryrefslogtreecommitdiff
path: root/uniform.c
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2024-05-17 08:55:48 +0200
committerlonkaars <loek@pipeframe.xyz>2024-05-17 08:55:48 +0200
commitaa9601e577e5ce7ac02f28b0a6f2d5dffc901c5f (patch)
treeac103be156c568a3758757ed65dedbc09cbc3b6b /uniform.c
parentf6ce5684117032e6a42a769c01a339e80d945841 (diff)
clean up uniform init/update code + fix window resizing
Diffstat (limited to 'uniform.c')
-rw-r--r--uniform.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/uniform.c b/uniform.c
new file mode 100644
index 0000000..6c66b7a
--- /dev/null
+++ b/uniform.c
@@ -0,0 +1,40 @@
+#include <sys/time.h>
+#include <time.h>
+#include <GL/glew.h>
+
+#include "uniform.h"
+
+int time_start = 0;
+GLFWwindow* window = NULL;
+GLint u_time, u_window;
+
+void init_uniform(GLuint shader, GLFWwindow* _window) {
+ window = _window;
+
+ u_time = glGetUniformLocation(shader, "time");
+ u_window = glGetUniformLocation(shader, "window");
+
+ time_start = time(NULL);
+}
+
+/** @brief update `uniform float time` */
+static void update_u_time() {
+ struct timeval t;
+ gettimeofday(&t, NULL);
+ t.tv_sec -= time_start;
+ float time = t.tv_sec + (t.tv_usec / 1e6);
+ glUniform1f(u_time, time);
+}
+
+/** @brief update `uniform ivec2 window` */
+static void update_u_window() {
+ int width, height;
+ glfwGetWindowSize(window, &width, &height);
+ glUniform2i(u_window, width, height);
+}
+
+void update_uniform() {
+ update_u_time();
+ update_u_window();
+}
+