aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c13
-rw-r--r--makefile7
-rw-r--r--visuals.frag12
3 files changed, 29 insertions, 3 deletions
diff --git a/main.c b/main.c
index 09cf2fb..c4da904 100644
--- a/main.c
+++ b/main.c
@@ -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);
diff --git a/makefile b/makefile
index fa39ee9..daf3750 100644
--- a/makefile
+++ b/makefile
@@ -4,6 +4,9 @@ LDFLAGS += -lGLEW
CFLAGS += -g
+GLFLAGS += --target-env=opengl
+GLFLAGS += -fauto-map-locations
+
.PHONY: FORCE
.SECONDARY: # do not remove intermediate files
@@ -23,9 +26,9 @@ main.o: visuals_frag.h
./blob $< $*
%_frag.spv: %.frag
- glslc -o $@ $<
+ glslc $(GLFLAGS) -o $@ $<
%_vert.spv: %.vert
- glslc -o $@ $<
+ glslc $(GLFLAGS) -o $@ $<
clean: FORCE
git clean -fxdi
diff --git a/visuals.frag b/visuals.frag
index 3539bdc..16e7712 100644
--- a/visuals.frag
+++ b/visuals.frag
@@ -2,7 +2,17 @@
#include "config.h"
+uniform float time;
+
+// adapted from <https://www.shadertoy.com/view/4djSRW>
+float hash12(vec2 p) {
+ vec3 p3 = fract(vec3(p.xyx) * .1031);
+ p3 += dot(p3, p3.yzx + 33.33);
+ return fract((p3.x + p3.y) * p3.z);
+}
+
void main() {
- gl_FragColor = vec4(gl_FragCoord.x / WIDTH, gl_FragCoord.y / HEIGHT, 0, 1);
+ vec2 pos = gl_FragCoord.xy + time;
+ gl_FragColor = vec4(vec3(hash12(pos)), 1.0);
}