summaryrefslogtreecommitdiffstats
path: root/glslwrite.c
diff options
context:
space:
mode:
Diffstat (limited to 'glslwrite.c')
-rw-r--r--glslwrite.c58
1 files changed, 50 insertions, 8 deletions
diff --git a/glslwrite.c b/glslwrite.c
index 2913ae8..6673146 100644
--- a/glslwrite.c
+++ b/glslwrite.c
@@ -27,6 +27,7 @@
#include <stdbool.h>
#include <stdio.h>
+#include <unistd.h>
#include <png.h>
@@ -36,12 +37,17 @@
#include <SDL2/SDL_opengl.h>
+static float step = 20;
+static unsigned frame = 0;
+static unsigned max_frame = 0;
+
+
static void savePNG(int width, int height, const char *output_dir) {
uint8_t pixels[width*height*4];
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, (unsigned)current_time);
+ snprintf(filename, sizeof(filename), "%s/%010u.png", output_dir, frame);
FILE *f = fopen(filename, "wb");
if (!f) {
@@ -84,12 +90,47 @@ static void savePNG(int width, int height, const char *output_dir) {
fclose(f);
}
+static void usage(void) {
+ fprintf(stderr, "Usage: glslwrite [-s <step>] [-f <frames>] [-0 <param0>] [-1 <param1>] [-2 <param2>] <shader>\n");
+ exit(1);
+}
+
int main(int argc, char *argv[]) {
- if (argc != 3) {
- fprintf(stderr, "Usage: glslwrite <shader> <output directory>\n");
- exit(1);
+ while (true) {
+ int c = getopt(argc, argv, "s:f:0:1:2:");
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 's':
+ step = atof(optarg);
+ break;
+
+ case 'f':
+ max_frame = atoi(optarg);
+ break;
+
+ case '0':
+ param0 = atoi(optarg);
+ break;
+
+ case '1':
+ param1 = atoi(optarg);
+ break;
+
+ case '2':
+ param2 = atoi(optarg);
+ break;
+
+ default:
+ fprintf(stderr, "Invalid option '%c'\n", optopt);
+ usage();
+ }
}
+ if (argc - optind != 2)
+ usage();
+
SDL_Init(SDL_INIT_VIDEO);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
@@ -100,11 +141,11 @@ int main(int argc, char *argv[]) {
SDL_Window *window = SDL_CreateWindow("glslwrite", 0, 0, 800, 800, SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE);
SDL_GLContext ctx = SDL_GL_CreateContext(window);
- filename = argv[1];
+ filename = argv[optind];
init();
load();
- while (true) {
+ while (!max_frame || frame < max_frame) {
SDL_Event e;
while (SDL_PollEvent(&e)) {
@@ -128,8 +169,9 @@ int main(int argc, char *argv[]) {
render(width, height);
SDL_GL_SwapWindow(window);
- savePNG(width, height, argv[2]);
- current_time += 20;
+ savePNG(width, height, argv[optind+1]);
+ current_time += step;
+ frame++;
}
quit: