From 05e2f21d27c4a8557e1afc61450414ec53cd48bb Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 4 Feb 2016 19:29:49 +0100 Subject: [PATCH 01/10] Print speed and parameters on changes --- glslview.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/glslview.c b/glslview.c index 42c9e93..05d0637 100644 --- a/glslview.c +++ b/glslview.c @@ -96,7 +96,15 @@ static void update(void) { unsigned ticks = SDL_GetTicks(); current_time += speed * (ticks - previous_ticks); previous_ticks = ticks; +} +static void set_speed(float v) { + speed = v; + printf("speed: %f\n", v); +} + +static void print_params(void) { + printf("params: %i %i %i\n", (int)param0, (int)param1, (int)param2); } static void handle_input(const char *input) { @@ -113,31 +121,32 @@ static void handle_input(const char *input) { case 'R': param0 = param1 = param2 = 0; + print_params(); break; case '+': - speed *= 1.1; + set_speed(speed * 1.1); break; case '-': - speed /= 1.1; + set_speed(speed / 1.1); break; case '=': if (speed < 0) - speed = -1.0; + set_speed(-1.0); else - speed = 1.0; + set_speed(1.0); break; case '<': if (speed > 0) - speed = -speed; + set_speed(-speed); break; case '>': if (speed < 0) - speed = -speed; + set_speed(-speed); } } } @@ -175,26 +184,32 @@ int main(int argc, char *argv[]) { switch (e.key.keysym.sym) { case SDLK_PAGEDOWN: param0++; + print_params(); break; case SDLK_PAGEUP: param0--; + print_params(); break; case SDLK_RIGHT: param1++; + print_params(); break; case SDLK_LEFT: param1--; + print_params(); break; case SDLK_DOWN: param2++; + print_params(); break; case SDLK_UP: param2--; + print_params(); break; case SDLK_ESCAPE: @@ -207,7 +222,7 @@ int main(int argc, char *argv[]) { break; case SDL_MOUSEWHEEL: - speed /= pow(1.1, e.wheel.y); + set_speed(speed / pow(1.1, e.wheel.y)); break; case SDL_QUIT: From d521cc0e83b279f4cd7a10a1704b8f36827a118d Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 4 Feb 2016 20:00:02 +0100 Subject: [PATCH 02/10] Remove unneeded headers from common.h, improve error handling --- common.c | 6 +++--- common.h | 11 +++-------- glslview.c | 18 +++++++++++------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/common.c b/common.c index e9258c1..b459f31 100644 --- a/common.c +++ b/common.c @@ -36,9 +36,9 @@ char *filename; float current_time = 0; -GLint param0 = 0; -GLint param1 = 0; -GLint param2 = 0; +int param0 = 0; +int param1 = 0; +int param2 = 0; static GLint time_loc; diff --git a/common.h b/common.h index 7cbf34d..8f45105 100644 --- a/common.h +++ b/common.h @@ -25,18 +25,13 @@ #pragma once -#include - -#include -#include - extern char *filename; extern float current_time; -extern GLint param0; -extern GLint param1; -extern GLint param2; +extern int param0; +extern int param1; +extern int param2; void load(void); diff --git a/glslview.c b/glslview.c index 05d0637..18cc512 100644 --- a/glslview.c +++ b/glslview.c @@ -25,14 +25,20 @@ #include "common.h" - +#include #include #include #include #include #include +#include #include +#include + +#include +#include + #ifdef USE_INOTIFY # include # include @@ -53,22 +59,20 @@ static int inotify_watch = -1; static void reset_watch(void) { if (inotify_watch >= 0) { if (inotify_rm_watch(inotify_fd, inotify_watch)) { - fprintf(stderr, "unable to remove watch\n"); + fprintf(stderr, "unable to remove watch: %s\n", strerror(errno)); exit(1); } } inotify_watch = inotify_add_watch(inotify_fd, filename, IN_CLOSE_WRITE); - if (inotify_watch < 0) { - fprintf(stderr, "unable to watch '%s' for changes\n", filename); - return; - } + if (inotify_watch < 0) + fprintf(stderr, "unable to watch '%s' for changes: %s\n", filename, strerror(errno)); } static void init_watch(void) { inotify_fd = inotify_init(); if (inotify_fd < 0) { - fprintf(stderr, "unable to initialize inotify\n"); + fprintf(stderr, "unable to initialize inotify: %s\n", strerror(errno)); exit(1); } From b65b7424030628a73c79999fc7c331a3032dbc96 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 6 Feb 2016 11:07:16 +0100 Subject: [PATCH 03/10] Makefile improvements --- Makefile | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 3826d3e..1b40d7c 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,17 @@ all : glslview glslwrite -USE_INOTIFY = -DUSE_INOTIFY +ifeq ($(shell uname -s),Linux) +USE_INOTIFY ?= -DUSE_INOTIFY +endif -CFLAGS = -O3 -Wall $(USE_INOTIFY) -LIBS = -lSDL2 -lGL -lGLEW -lm +CFLAGS ?= -O3 -Wall +LIBS := -lSDL2 -lGL -lGLEW -lm glslview : glslview.c common.c common.h - $(CC) $(CFLAGS) -o $@ glslview.c common.c $(LIBS) + $(CC) $(CFLAGS) $(USE_INOTIFY) -o $@ glslview.c common.c $(LIBS) glslwrite : glslwrite.c common.c common.h $(CC) $(CFLAGS) -o $@ glslwrite.c common.c $(LIBS) -lpng + +clean : + rm -f glslview glslwrite From 1ec5502d46690439b2989653fa39978227914539 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 6 Feb 2016 11:13:28 +0100 Subject: [PATCH 04/10] Add pause function --- glslview.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/glslview.c b/glslview.c index 18cc512..4ff4dd3 100644 --- a/glslview.c +++ b/glslview.c @@ -46,6 +46,7 @@ #endif +static bool paused = false; static float speed = 1.0; static unsigned previous_ticks = 0; @@ -98,7 +99,10 @@ static void check_reload(void) {} static void update(void) { unsigned ticks = SDL_GetTicks(); - current_time += speed * (ticks - previous_ticks); + + if (!paused) + current_time += speed * (ticks - previous_ticks); + previous_ticks = ticks; } @@ -151,6 +155,10 @@ static void handle_input(const char *input) { case '>': if (speed < 0) set_speed(-speed); + break; + + case ' ': + paused = !paused; } } } From ee22df92112d6309adc8b0ed1b8d5624a68e27e9 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 6 Feb 2016 11:39:37 +0100 Subject: [PATCH 05/10] Add command line options --- glslview.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++------- glslwrite.c | 58 ++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 102 insertions(+), 16 deletions(-) diff --git a/glslview.c b/glslview.c index 4ff4dd3..b0b5d1b 100644 --- a/glslview.c +++ b/glslview.c @@ -46,6 +46,12 @@ #endif +static int init_param0 = 0; +static int init_param1 = 0; +static int init_param2 = 0; +static float init_time = 0; +static float init_speed = 1.0; + static bool paused = false; static float speed = 1.0; static unsigned previous_ticks = 0; @@ -124,11 +130,13 @@ static void handle_input(const char *input) { break; case 'r': - current_time = 0; + current_time = init_time; break; case 'R': - param0 = param1 = param2 = 0; + param0 = init_param0; + param1 = init_param1; + param2 = init_param2; print_params(); break; @@ -142,9 +150,9 @@ static void handle_input(const char *input) { case '=': if (speed < 0) - set_speed(-1.0); + set_speed(-init_speed); else - set_speed(1.0); + set_speed(init_speed); break; case '<': @@ -163,12 +171,48 @@ static void handle_input(const char *input) { } } +static void usage(void) { + fprintf(stderr, "Usage: glslview [-t