diff options
Diffstat (limited to 'glslview.c')
-rw-r--r-- | glslview.c | 60 |
1 files changed, 52 insertions, 8 deletions
@@ -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 <time>] [-s <speed>] [-0 <param0>] [-1 <param1>] [-2 <param2>] <shader>\n"); + exit(1); +} + int main(int argc, char *argv[]) { - if (argc != 2) { - fprintf(stderr, "Usage: glslview <shader>\n"); - exit(1); + while (true) { + int c = getopt(argc, argv, "t:s:0:1:2:"); + if (c == -1) + break; + + switch (c) { + case 't': + current_time = init_time = atof(optarg); + break; + + case 's': + speed = atof(optarg); + init_speed = fabsf(speed); + break; + + case '0': + param0 = init_param0 = atoi(optarg); + break; + + case '1': + param1 = init_param1 = atoi(optarg); + break; + + case '2': + param2 = init_param2 = atoi(optarg); + break; + + default: + fprintf(stderr, "Invalid option '%c'\n", optopt); + usage(); + } } + if (argc - optind != 1) + usage(); + SDL_Init(SDL_INIT_VIDEO); SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); @@ -179,7 +223,7 @@ int main(int argc, char *argv[]) { SDL_Window *window = SDL_CreateWindow("glslview", 0, 0, 800, 800, SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE); SDL_GLContext ctx = SDL_GL_CreateContext(window); - filename = argv[1]; + filename = argv[optind]; init_watch(); init(); |