- 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, -1.65, 0);
- glMatrixMode(GL_MODELVIEW);
- glLoadMatrixf(view_mat[0]);
-
- //mesh_torus->draw();
-
- Mat4 xform;
- xform.scaling(500.0);
- glPushMatrix();
- glMultMatrixf(xform[0]);
-
- bind_program(sdr_grid);
- glBegin(GL_QUADS);
- glNormal3f(0, 1, 0);
- glVertex3f(-1, 0, 1);
- glVertex3f(1, 0, 1);
- glVertex3f(1, 0, -1);
- glVertex3f(-1, 0, -1);
- glEnd();
- bind_program(0);
-
- glPopMatrix();
-
- app_swap_buffers();
+ if(opt.vr) {
+ // VR mode
+ goatvr_draw_start();
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ for(int i=0; i<2; i++) {
+ goatvr_draw_eye(i);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadMatrixf(goatvr_projection_matrix(i, 0.5, 1000.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_matrix[0]);
+
+ draw_backdrop();
+ }
+ goatvr_draw_done();
+
+ if(should_swap) {
+ app_swap_buffers();
+ }
+ app_redraw(); // in VR mode, force continuous redraw
+
+ } else {
+ // regular monoscopic mode
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ 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_matrix[0]);
+
+ draw_backdrop();
+
+ app_swap_buffers();
+ app_redraw(); // since we added animation we need to redisplay even in non-VR mode
+ }