summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2016-02-02 09:00:05 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2016-02-02 09:00:05 +0100
commitf81f0074c0db900cbc44113d457a2395d3a55fd1 (patch)
treece7dcf850573fb648f7593f28c256c0260220b7d
parent709e22459b6de9c28c4b4c10fde1b129b0558cd1 (diff)
downloadglslview-f81f0074c0db900cbc44113d457a2395d3a55fd1.tar
glslview-f81f0074c0db900cbc44113d457a2395d3a55fd1.zip
Add support for changing the speed
-rw-r--r--Makefile5
-rw-r--r--glslview.c67
2 files changed, 57 insertions, 15 deletions
diff --git a/Makefile b/Makefile
index c79d1a5..11a990e 100644
--- a/Makefile
+++ b/Makefile
@@ -3,9 +3,10 @@ all : glslview glslwrite
USE_INOTIFY = -DUSE_INOTIFY
CFLAGS = -O3 -Wall $(USE_INOTIFY)
+LIBS = -lSDL2 -lGL -lGLEW -lm
glslview : glslview.c
- $(CC) $(CFLAGS) -o $@ $^ -lSDL2 -lGL -lGLEW
+ $(CC) $(CFLAGS) -o $@ $^ $(LIBS)
glslwrite : glslview.c
- $(CC) $(CFLAGS) -o $@ $^ -DGLSLWRITE -lSDL2 -lpng -lGL -lGLEW
+ $(CC) $(CFLAGS) -DGLSLWRITE -o $@ $^ $(LIBS) -lpng
diff --git a/glslview.c b/glslview.c
index b443522..6918fa0 100644
--- a/glslview.c
+++ b/glslview.c
@@ -1,5 +1,6 @@
#include <fcntl.h>
#include <limits.h>
+#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
@@ -27,7 +28,9 @@ static unsigned frame_time = 0;
#else
-static unsigned time_orig = 0;
+static float speed = 1.0;
+static float current_time = 0;
+static unsigned previous_ticks = 0;
#ifdef USE_INOTIFY
static int inotify_fd = -1;
@@ -222,10 +225,19 @@ static void render(int width, int height) {
glViewport(0, 0, (GLsizei)width, (GLsizei)height);
#ifdef GLSLWRITE
+
glUniform1f(time_loc, frame_time);
+
#else
- glUniform1f(time_loc, SDL_GetTicks() - time_orig);
+
+ unsigned ticks = SDL_GetTicks();
+ current_time += speed * (ticks - previous_ticks);
+ previous_ticks = ticks;
+
+ glUniform1f(time_loc, current_time);
+
#endif
+
glUniform2f(res_loc, width, height);
glBegin(GL_QUADS);
@@ -240,6 +252,35 @@ static void render(int width, int height) {
#endif
}
+#ifndef GLSLWRITE
+static void handle_input(const char *input) {
+ for (; *input; input++) {
+ switch (*input) {
+ case 'l':
+#ifdef USE_INOTIFY
+ reset_watch();
+#endif
+ load();
+ break;
+
+ case 'r':
+ current_time = 0;
+ break;
+
+ case '+':
+ speed *= 1.1;
+ break;
+
+ case '-':
+ speed /= 1.1;
+ break;
+
+ case '=':
+ speed = 1.0;
+ }
+ }
+}
+#endif
int main(int argc, char *argv[]) {
#ifdef GLSLWRITE
@@ -267,6 +308,8 @@ int main(int argc, char *argv[]) {
filename = argv[1];
init();
+ SDL_StartTextInput();
+
while (true) {
SDL_Event e;
@@ -276,21 +319,18 @@ int main(int argc, char *argv[]) {
switch (e.key.keysym.sym) {
case SDLK_ESCAPE:
goto quit;
+ }
+ break;
#ifndef GLSLWRITE
- case SDLK_l:
-#ifdef USE_INOTIFY
- reset_watch();
-#endif
- load();
- break;
+ case SDL_TEXTINPUT:
+ handle_input(e.text.text);
+ break;
- case SDLK_r:
- time_orig = SDL_GetTicks();
- break;
-#endif
- }
+ case SDL_MOUSEWHEEL:
+ speed /= pow(1.1, e.wheel.y);
break;
+#endif
case SDL_QUIT:
goto quit;
@@ -311,6 +351,7 @@ int main(int argc, char *argv[]) {
}
quit:
+ SDL_StopTextInput();
SDL_GL_DeleteContext(ctx);
SDL_DestroyWindow(window);
SDL_Quit();