5 #include "gmath/gmath.h"
12 int win_width, win_height;
17 static bool should_swap;
19 static float cam_theta, cam_phi;
20 static float cam_height = 1.65;
21 static Mesh *mesh_torus;
23 static bool bnstate[16];
24 static int prev_x, prev_y;
26 bool app_init(int argc, char **argv)
28 if(!init_options(argc, argv, 0)) {
31 if(init_opengl() == -1) {
35 glEnable(GL_MULTISAMPLE);
38 glGetIntegerv(GL_SAMPLES, &aasamples);
39 printf("got %d samples per pixel\n", aasamples);
41 printf("Max anisotropy: %d\n", glcaps.max_aniso);
43 glEnable(GL_CULL_FACE);
44 glEnable(GL_DEPTH_TEST);
46 if(opt.srgb && GLEW_ARB_framebuffer_sRGB) {
47 printf("enabling sRGB framebuffer\n");
48 glEnable(GL_FRAMEBUFFER_SRGB);
52 if(goatvr_init() == -1) {
55 goatvr_set_origin_mode(GOATVR_HEAD);
58 should_swap = goatvr_should_swap() != 0;
59 cam_height = goatvr_get_eye_height();
62 Mesh::use_custom_sdr_attr = false;
64 mesh_torus = new Mesh;
65 gen_torus(mesh_torus, 1.0, 0.25, 32, 32);
67 if(!init_backdrop()) {
88 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
90 for(int i=0; i<2; i++) {
93 glMatrixMode(GL_PROJECTION);
94 glLoadMatrixf(goatvr_projection_matrix(i, 0.5, 1000.0));
96 view_matrix = goatvr_view_matrix(i);
97 view_matrix.pre_rotate_x(deg_to_rad(cam_phi));
98 view_matrix.pre_rotate_y(deg_to_rad(cam_theta));
99 view_matrix.pre_translate(0, -cam_height, 0);
101 glMatrixMode(GL_MODELVIEW);
102 glLoadMatrixf(view_matrix[0]);
111 app_redraw(); // in VR mode, force continuous redraw
114 // regular monoscopic mode
115 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
117 view_matrix = Mat4::identity;
118 view_matrix.pre_rotate_x(deg_to_rad(cam_phi));
119 view_matrix.pre_rotate_y(deg_to_rad(cam_theta));
120 view_matrix.pre_translate(0, -cam_height, 0);
122 glMatrixMode(GL_MODELVIEW);
123 glLoadMatrixf(view_matrix[0]);
129 assert(glGetError() == GL_NO_ERROR);
132 void app_reshape(int x, int y)
134 glViewport(0, 0, x, y);
137 mat.perspective(deg_to_rad(50), win_aspect, 0.5, 500.0);
139 glMatrixMode(GL_PROJECTION);
140 glLoadMatrixf(mat[0]);
143 void app_keyboard(int key, bool pressed)
160 void app_mouse_button(int bn, bool pressed, int x, int y)
162 bnstate[bn] = pressed;
167 void app_mouse_motion(int x, int y)
174 if(!dx && !dy) return;
177 cam_theta += dx * 0.5;
179 if(!opt.vr || !goatvr_have_headtracking()) {
182 if(cam_phi < -90) cam_phi = -90;
183 if(cam_phi > 90) cam_phi = 90;