#include "meshgen.h"
#include "backdrop.h"
#include "goatvr.h"
+#include "opt.h"
+#include "fs.h"
-static bool parse_args(int argc, char **argv);
+static void draw_scene();
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;
static float cam_height = 1.65;
-static Mesh *mesh_torus;
static bool bnstate[16];
static int prev_x, prev_y;
bool app_init(int argc, char **argv)
{
- if(!parse_args(argc, argv)) {
+ if(!init_options(argc, argv, "vrfileman.conf")) {
return false;
}
+ app_resize(opt.width, opt.height);
+ app_fullscreen(opt.fullscreen);
+
if(init_opengl() == -1) {
return false;
}
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;
}
Mesh::use_custom_sdr_attr = false;
- mesh_torus = new Mesh;
- gen_torus(mesh_torus, 1.0, 0.25, 32, 32);
-
if(!init_backdrop()) {
return false;
}
+ if(!init_fs()) {
+ return false;
+ }
+
return true;
}
void app_cleanup()
{
- if(use_vr) {
+ if(opt.vr) {
goatvr_shutdown();
}
- delete mesh_torus;
cleanup_backdrop();
}
void app_draw()
{
- if(use_vr) {
+ if(opt.vr) {
// VR mode
goatvr_draw_start();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(view_matrix[0]);
- draw_backdrop();
+ draw_scene();
}
goatvr_draw_done();
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(view_matrix[0]);
- draw_backdrop();
+ draw_scene();
app_swap_buffers();
+ app_redraw(); // since we added animation we need to redisplay even in non-VR mode
}
assert(glGetError() == GL_NO_ERROR);
}
+static void draw_scene()
+{
+ draw_backdrop();
+ draw_fs();
+}
+
void app_reshape(int x, int y)
{
glViewport(0, 0, x, 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)
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;
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;
}
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;
-}