Some more glslview/glslwrite unification

This commit is contained in:
Matthias Schiffer 2016-02-02 09:34:10 +01:00
parent f81f0074c0
commit 6f023066fc

View file

@ -22,14 +22,9 @@
#include <SDL2/SDL_opengl.h> #include <SDL2/SDL_opengl.h>
#ifdef GLSLWRITE #ifndef GLSLWRITE
static unsigned frame_time = 0;
#else
static float speed = 1.0; static float speed = 1.0;
static float current_time = 0;
static unsigned previous_ticks = 0; static unsigned previous_ticks = 0;
#ifdef USE_INOTIFY #ifdef USE_INOTIFY
@ -41,6 +36,7 @@ static int inotify_watch = -1;
static char *filename; static char *filename;
static float current_time = 0;
static GLint time_loc; static GLint time_loc;
static GLint res_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); glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, pixels);
char filename[strlen(output_dir) + 20]; 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"); FILE *f = fopen(filename, "wb");
if (!f) { if (!f) {
@ -224,20 +220,13 @@ static void savePNG(int width, int height, const char *output_dir) {
static void render(int width, int height) { static void render(int width, int height) {
glViewport(0, 0, (GLsizei)width, (GLsizei)height); glViewport(0, 0, (GLsizei)width, (GLsizei)height);
#ifdef GLSLWRITE #ifndef GLSLWRITE
glUniform1f(time_loc, frame_time);
#else
unsigned ticks = SDL_GetTicks(); unsigned ticks = SDL_GetTicks();
current_time += speed * (ticks - previous_ticks); current_time += speed * (ticks - previous_ticks);
previous_ticks = ticks; previous_ticks = ticks;
glUniform1f(time_loc, current_time);
#endif #endif
glUniform1f(time_loc, current_time);
glUniform2f(res_loc, width, height); glUniform2f(res_loc, width, height);
glBegin(GL_QUADS); glBegin(GL_QUADS);
@ -246,10 +235,6 @@ static void render(int width, int height) {
glVertex2f(1, 1); glVertex2f(1, 1);
glVertex2f(-1, 1); glVertex2f(-1, 1);
glEnd(); glEnd();
#ifdef GLSLWRITE
frame_time += 20;
#endif
} }
#ifndef GLSLWRITE #ifndef GLSLWRITE
@ -347,6 +332,7 @@ int main(int argc, char *argv[]) {
#ifdef GLSLWRITE #ifdef GLSLWRITE
savePNG(width, height, argv[2]); savePNG(width, height, argv[2]);
current_time += 20;
#endif #endif
} }