From 6f023066fc9712c5bbed1b0220439e304b13f10c Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 2 Feb 2016 09:34:10 +0100 Subject: Some more glslview/glslwrite unification --- glslview.c | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/glslview.c b/glslview.c index 6918fa0..fd0b180 100644 --- a/glslview.c +++ b/glslview.c @@ -22,14 +22,9 @@ #include -#ifdef GLSLWRITE - -static unsigned frame_time = 0; - -#else +#ifndef GLSLWRITE static float speed = 1.0; -static float current_time = 0; static unsigned previous_ticks = 0; #ifdef USE_INOTIFY @@ -41,6 +36,7 @@ static int inotify_watch = -1; static char *filename; +static float current_time = 0; static GLint time_loc; static GLint res_loc; @@ -177,7 +173,7 @@ static void savePNG(int width, int height, const char *output_dir) { glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, pixels); char filename[strlen(output_dir) + 20]; - snprintf(filename, sizeof(filename), "%s/%010u.png", output_dir, frame_time); + snprintf(filename, sizeof(filename), "%s/%010u.png", output_dir, (unsigned)current_time); FILE *f = fopen(filename, "wb"); if (!f) { @@ -224,20 +220,13 @@ static void savePNG(int width, int height, const char *output_dir) { static void render(int width, int height) { glViewport(0, 0, (GLsizei)width, (GLsizei)height); -#ifdef GLSLWRITE - - glUniform1f(time_loc, frame_time); - -#else - +#ifndef GLSLWRITE unsigned ticks = SDL_GetTicks(); current_time += speed * (ticks - previous_ticks); previous_ticks = ticks; - - glUniform1f(time_loc, current_time); - #endif + glUniform1f(time_loc, current_time); glUniform2f(res_loc, width, height); glBegin(GL_QUADS); @@ -246,10 +235,6 @@ static void render(int width, int height) { glVertex2f(1, 1); glVertex2f(-1, 1); glEnd(); - -#ifdef GLSLWRITE - frame_time += 20; -#endif } #ifndef GLSLWRITE @@ -347,6 +332,7 @@ int main(int argc, char *argv[]) { #ifdef GLSLWRITE savePNG(width, height, argv[2]); + current_time += 20; #endif } -- cgit v1.2.3