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 static float fov = 60.0;
31 bool app_init(int argc, char **argv)
33 if(!init_options(argc, argv, "vrfileman.conf")) {
36 app_resize(opt.width, opt.height);
37 app_fullscreen(opt.fullscreen);
39 if(init_opengl() == -1) {
43 glEnable(GL_MULTISAMPLE);
46 glGetIntegerv(GL_SAMPLES, &aasamples);
47 printf("got %d samples per pixel\n", aasamples);
49 printf("Max anisotropy: %d\n", glcaps.max_aniso);
51 glEnable(GL_CULL_FACE);
52 glEnable(GL_DEPTH_TEST);
54 if(opt.srgb && GLEW_ARB_framebuffer_sRGB) {
55 printf("enabling sRGB framebuffer\n");
56 glEnable(GL_FRAMEBUFFER_SRGB);
60 if(goatvr_init() == -1) {
63 goatvr_set_origin_mode(GOATVR_HEAD);
66 should_swap = goatvr_should_swap() != 0;
67 cam_height = goatvr_get_eye_height();
70 Mesh::use_custom_sdr_attr = false;
72 if(!init_backdrop()) {
76 if(!init_fs(opt.path)) {
96 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
98 for(int i=0; i<2; i++) {
101 glMatrixMode(GL_PROJECTION);
102 glLoadMatrixf(goatvr_projection_matrix(i, 0.1, 200.0));
104 view_matrix = goatvr_view_matrix(i);
105 view_matrix.pre_rotate_x(deg_to_rad(cam_phi));
106 view_matrix.pre_rotate_y(deg_to_rad(cam_theta));
107 view_matrix.pre_translate(0, -cam_height, 0);
109 glMatrixMode(GL_MODELVIEW);
110 glLoadMatrixf(view_matrix[0]);
119 app_redraw(); // in VR mode, force continuous redraw
122 // regular monoscopic mode
123 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
126 mat.perspective(deg_to_rad(fov), win_aspect, 0.1, 200.0);
127 glMatrixMode(GL_PROJECTION);
128 glLoadMatrixf(mat[0]);
130 view_matrix = Mat4::identity;
131 view_matrix.pre_rotate_x(deg_to_rad(cam_phi));
132 view_matrix.pre_rotate_y(deg_to_rad(cam_theta));
133 view_matrix.pre_translate(0, -cam_height, 0);
135 glMatrixMode(GL_MODELVIEW);
136 glLoadMatrixf(view_matrix[0]);
141 app_redraw(); // since we added animation we need to redisplay even in non-VR mode
143 assert(glGetError() == GL_NO_ERROR);
146 static void draw_scene()
152 void app_reshape(int x, int y)
154 glViewport(0, 0, x, y);
157 goatvr_set_fb_size(x, y, 1.0);
161 void app_keyboard(int key, bool pressed)
170 if(!opt.vr || should_swap) {
171 /* we take the need to swap as a signal that our window is not managed
172 * by some VR compositor, and therefore it's safe to fullscreen without
173 * upsetting the VR rendering output
175 opt.fullscreen = !opt.fullscreen;
176 app_fullscreen(opt.fullscreen);
188 if(fov > 160.0) fov = 160.0;
193 if(fov < 0.0) fov = 0.0;
199 void app_mouse_button(int bn, bool pressed, int x, int y)
201 bnstate[bn] = pressed;
206 void app_mouse_motion(int x, int y)
213 if(!dx && !dy) return;
216 cam_theta += dx * 0.5;
218 if(!opt.vr || !goatvr_have_headtracking()) {
221 if(cam_phi < -90) cam_phi = -90;
222 if(cam_phi > 90) cam_phi = 90;