#include #include #include #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(); }