5 #include "gmath/gmath.h"
13 static void draw_scene();
15 int win_width, win_height;
21 static bool should_swap;
23 static float cam_theta, cam_phi;
24 static float cam_height = 1.65;
26 static bool bnstate[16];
27 static int prev_x, prev_y;
29 bool app_init(int argc, char **argv)
31 if(!init_options(argc, argv, "vrfileman.conf")) {
34 app_resize(opt.width, opt.height);
35 app_fullscreen(opt.fullscreen);
37 if(init_opengl() == -1) {
41 glEnable(GL_MULTISAMPLE);
44 glGetIntegerv(GL_SAMPLES, &aasamples);
45 printf("got %d samples per pixel\n", aasamples);
47 printf("Max anisotropy: %d\n", glcaps.max_aniso);
49 glEnable(GL_CULL_FACE);
50 glEnable(GL_DEPTH_TEST);
52 if(opt.srgb && GLEW_ARB_framebuffer_sRGB) {
53 printf("enabling sRGB framebuffer\n");
54 glEnable(GL_FRAMEBUFFER_SRGB);
58 if(goatvr_init() == -1) {
61 goatvr_set_origin_mode(GOATVR_HEAD);
64 should_swap = goatvr_should_swap() != 0;
65 cam_height = goatvr_get_eye_height();
68 Mesh::use_custom_sdr_attr = false;
70 if(!init_backdrop()) {
74 if(!init_fs(opt.path)) {
94 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
96 for(int i=0; i<2; i++) {
99 glMatrixMode(GL_PROJECTION);
100 glLoadMatrixf(goatvr_projection_matrix(i, 0.1, 200.0));
102 view_matrix = goatvr_view_matrix(i);
103 view_matrix.pre_rotate_x(deg_to_rad(cam_phi));
104 view_matrix.pre_rotate_y(deg_to_rad(cam_theta));
105 view_matrix.pre_translate(0, -cam_height, 0);
107 glMatrixMode(GL_MODELVIEW);
108 glLoadMatrixf(view_matrix[0]);
117 app_redraw(); // in VR mode, force continuous redraw
120 // regular monoscopic mode
121 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
123 view_matrix = Mat4::identity;
124 view_matrix.pre_rotate_x(deg_to_rad(cam_phi));
125 view_matrix.pre_rotate_y(deg_to_rad(cam_theta));
126 view_matrix.pre_translate(0, -cam_height, 0);
128 glMatrixMode(GL_MODELVIEW);
129 glLoadMatrixf(view_matrix[0]);
134 app_redraw(); // since we added animation we need to redisplay even in non-VR mode
136 assert(glGetError() == GL_NO_ERROR);
139 static void draw_scene()
145 void app_reshape(int x, int y)
147 glViewport(0, 0, x, y);
150 mat.perspective(deg_to_rad(60), win_aspect, 0.1, 200.0);
152 glMatrixMode(GL_PROJECTION);
153 glLoadMatrixf(mat[0]);
156 goatvr_set_fb_size(x, y, 1.0);
160 void app_keyboard(int key, bool pressed)
169 if(!opt.vr || should_swap) {
170 /* we take the need to swap as a signal that our window is not managed
171 * by some VR compositor, and therefore it's safe to fullscreen without
172 * upsetting the VR rendering output
174 opt.fullscreen = !opt.fullscreen;
175 app_fullscreen(opt.fullscreen);
188 void app_mouse_button(int bn, bool pressed, int x, int y)
190 bnstate[bn] = pressed;
195 void app_mouse_motion(int x, int y)
202 if(!dx && !dy) return;
205 cam_theta += dx * 0.5;
207 if(!opt.vr || !goatvr_have_headtracking()) {
210 if(cam_phi < -90) cam_phi = -90;
211 if(cam_phi > 90) cam_phi = 90;