added more options
[vrfileman] / src / app.cc
index d8aa144..730302e 100644 (file)
@@ -7,14 +7,13 @@
 #include "meshgen.h"
 #include "backdrop.h"
 #include "goatvr.h"
-
-static bool parse_args(int argc, char **argv);
+#include "opt.h"
 
 int win_width, win_height;
 float win_aspect;
 long time_msec;
+Mat4 view_matrix;
 
-static bool use_vr;
 static bool should_swap;
 
 static float cam_theta, cam_phi;
@@ -26,9 +25,12 @@ static int prev_x, prev_y;
 
 bool app_init(int argc, char **argv)
 {
-       if(!parse_args(argc, argv)) {
+       if(!init_options(argc, argv, 0)) {
                return false;
        }
+       app_resize(opt.width, opt.height);
+       app_fullscreen(opt.fullscreen);
+
        if(init_opengl() == -1) {
                return false;
        }
@@ -39,16 +41,17 @@ bool app_init(int argc, char **argv)
        glGetIntegerv(GL_SAMPLES, &aasamples);
        printf("got %d samples per pixel\n", aasamples);
 
+       printf("Max anisotropy: %d\n", glcaps.max_aniso);
+
        glEnable(GL_CULL_FACE);
        glEnable(GL_DEPTH_TEST);
-       //glEnable(GL_LIGHTING);
-       glEnable(GL_LIGHT0);
 
-       if(GLEW_ARB_framebuffer_sRGB) {
+       if(opt.srgb && GLEW_ARB_framebuffer_sRGB) {
+               printf("enabling sRGB framebuffer\n");
                glEnable(GL_FRAMEBUFFER_SRGB);
        }
 
-       if(use_vr) {
+       if(opt.vr) {
                if(goatvr_init() == -1) {
                        return false;
                }
@@ -73,7 +76,7 @@ bool app_init(int argc, char **argv)
 
 void app_cleanup()
 {
-       if(use_vr) {
+       if(opt.vr) {
                goatvr_shutdown();
        }
        delete mesh_torus;
@@ -82,7 +85,7 @@ void app_cleanup()
 
 void app_draw()
 {
-       if(use_vr) {
+       if(opt.vr) {
                // VR mode
                goatvr_draw_start();
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -93,13 +96,13 @@ void app_draw()
                        glMatrixMode(GL_PROJECTION);
                        glLoadMatrixf(goatvr_projection_matrix(i, 0.5, 1000.0));
 
-                       Mat4 view_mat = goatvr_view_matrix(i);
-                       view_mat.pre_rotate_x(deg_to_rad(cam_phi));
-                       view_mat.pre_rotate_y(deg_to_rad(cam_theta));
-                       view_mat.pre_translate(0, -cam_height, 0);
+                       view_matrix = goatvr_view_matrix(i);
+                       view_matrix.pre_rotate_x(deg_to_rad(cam_phi));
+                       view_matrix.pre_rotate_y(deg_to_rad(cam_theta));
+                       view_matrix.pre_translate(0, -cam_height, 0);
 
                        glMatrixMode(GL_MODELVIEW);
-                       glLoadMatrixf(view_mat[0]);
+                       glLoadMatrixf(view_matrix[0]);
 
                        draw_backdrop();
                }
@@ -114,13 +117,13 @@ void app_draw()
                // regular monoscopic mode
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
-               Mat4 view_mat;
-               view_mat.pre_rotate_x(deg_to_rad(cam_phi));
-               view_mat.pre_rotate_y(deg_to_rad(cam_theta));
-               view_mat.pre_translate(0, -cam_height, 0);
+               view_matrix = Mat4::identity;
+               view_matrix.pre_rotate_x(deg_to_rad(cam_phi));
+               view_matrix.pre_rotate_y(deg_to_rad(cam_theta));
+               view_matrix.pre_translate(0, -cam_height, 0);
 
                glMatrixMode(GL_MODELVIEW);
-               glLoadMatrixf(view_mat[0]);
+               glLoadMatrixf(view_matrix[0]);
 
                draw_backdrop();
 
@@ -149,7 +152,7 @@ void app_keyboard(int key, bool pressed)
                        break;
 
                case ' ':
-                       if(use_vr) {
+                       if(opt.vr) {
                                goatvr_recenter();
                        }
                        break;
@@ -176,7 +179,7 @@ void app_mouse_motion(int x, int y)
        if(bnstate[0]) {
                cam_theta += dx * 0.5;
 
-               if(!use_vr || !goatvr_have_headtracking()) {
+               if(!opt.vr || !goatvr_have_headtracking()) {
                        cam_phi += dy * 0.5;
 
                        if(cam_phi < -90) cam_phi = -90;
@@ -185,30 +188,3 @@ void app_mouse_motion(int x, int y)
        }
        app_redraw();
 }
-
-static bool parse_args(int argc, char **argv)
-{
-       for(int i=1; i<argc; i++) {
-               if(argv[i][0] == '-') {
-                       if(strcmp(argv[i], "-vr") == 0) {
-                               use_vr = true;
-
-                       } else if(strcmp(argv[i], "-novr") == 0) {
-                               use_vr = false;
-
-                       } else if(strcmp(argv[i], "-help") == 0) {
-                               printf("usage: %s [options]\noptions:\n", argv[0]);
-                               printf(" -vr/-novr: enable/disable VR\n");
-                               printf(" -help: print usage information and exit\n");
-                               exit(0);
-                       } else {
-                               fprintf(stderr, "invalid option: %s\n", argv[i]);
-                               return false;
-                       }
-               } else {
-                       fprintf(stderr, "unexpected option: %s\n", argv[i]);
-                       return false;
-               }
-       }
-       return true;
-}