fullscreen switching and missing goatvr_set_fb_size call
[vrfileman] / src / app.cc
index 0dc88f0..c3f6b39 100644 (file)
@@ -7,15 +7,14 @@
 #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;
+double time_sec;
 Mat4 view_matrix;
 
-static bool use_vr;
 static bool should_swap;
 
 static float cam_theta, cam_phi;
@@ -27,9 +26,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;
        }
@@ -44,14 +46,13 @@ bool app_init(int argc, char **argv)
 
        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;
                }
@@ -76,7 +77,7 @@ bool app_init(int argc, char **argv)
 
 void app_cleanup()
 {
-       if(use_vr) {
+       if(opt.vr) {
                goatvr_shutdown();
        }
        delete mesh_torus;
@@ -85,7 +86,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);
@@ -128,6 +129,7 @@ void app_draw()
                draw_backdrop();
 
                app_swap_buffers();
+               app_redraw();   // since we added animation we need to redisplay even in non-VR mode
        }
        assert(glGetError() == GL_NO_ERROR);
 }
@@ -141,6 +143,10 @@ void app_reshape(int x, int y)
 
        glMatrixMode(GL_PROJECTION);
        glLoadMatrixf(mat[0]);
+
+       if(opt.vr) {
+               goatvr_set_fb_size(x, y, 1.0);
+       }
 }
 
 void app_keyboard(int key, bool pressed)
@@ -151,8 +157,19 @@ void app_keyboard(int key, bool pressed)
                        app_quit();
                        break;
 
+               case 'f':
+                       if(!opt.vr || should_swap) {
+                               /* we take the need to swap as a signal that our window is not managed
+                                * by some VR compositor, and therefore it's safe to fullscreen without
+                                * upsetting the VR rendering output
+                                */
+                               opt.fullscreen = !opt.fullscreen;
+                               app_fullscreen(opt.fullscreen);
+                       }
+                       break;
+
                case ' ':
-                       if(use_vr) {
+                       if(opt.vr) {
                                goatvr_recenter();
                        }
                        break;
@@ -179,7 +196,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;
@@ -188,30 +205,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;
-}