diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2016-02-02 09:00:05 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2016-02-02 09:00:05 +0100 |
commit | f81f0074c0db900cbc44113d457a2395d3a55fd1 (patch) | |
tree | ce7dcf850573fb648f7593f28c256c0260220b7d | |
parent | 709e22459b6de9c28c4b4c10fde1b129b0558cd1 (diff) | |
download | glslview-f81f0074c0db900cbc44113d457a2395d3a55fd1.tar glslview-f81f0074c0db900cbc44113d457a2395d3a55fd1.zip |
Add support for changing the speed
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | glslview.c | 67 |
2 files changed, 57 insertions, 15 deletions
@@ -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 @@ -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(); |