3 #include <cgmath/cgmath.h>
12 static void calc_framerate(void);
13 static void print_framerate(void);
15 float view_matrix[16], proj_matrix[16];
16 static int should_swap;
17 static unsigned long framerate;
19 int game_init(int argc, char **argv)
21 if(init_opengl() == -1) {
25 if(init_options(argc, argv, "vrtris.conf") == -1) {
29 if(init_screens() == -1) {
33 if(opt.flags & OPT_VR) {
34 if(goatvr_init() == -1) {
37 goatvr_set_origin_mode(GOATVR_HEAD);
40 should_swap = goatvr_should_swap();
48 if(opt.flags & OPT_VR) {
54 static void update(float dt)
58 if((num_vr_sticks = goatvr_num_sticks()) > 0) {
60 goatvr_stick_pos(0, p);
67 void game_display(void)
69 static long prev_msec;
71 float dt = (float)(time_msec - prev_msec) / 1000.0f;
72 prev_msec = time_msec;
76 if(opt.flags & OPT_VR) {
78 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
84 cgm_mcopy(proj_matrix, goatvr_projection_matrix(i, 0.5, 500.0));
85 glMatrixMode(GL_PROJECTION);
86 glLoadMatrixf(proj_matrix);
88 cgm_mcopy(view_matrix, goatvr_view_matrix(i));
89 glMatrixMode(GL_MODELVIEW);
90 glLoadMatrixf(view_matrix);
105 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
107 cgm_mperspective(proj_matrix, cgm_deg_to_rad(50.0), win_aspect, 0.5, 500.0);
108 glMatrixMode(GL_PROJECTION);
109 glLoadMatrixf(proj_matrix);
111 cgm_midentity(view_matrix);
112 glMatrixMode(GL_MODELVIEW);
113 glLoadMatrixf(view_matrix);
122 assert(glGetError() == GL_NO_ERROR);
127 void game_reshape(int x, int y)
129 glViewport(0, 0, x, y);
130 goatvr_set_fb_size(x, y, 1.0f);
132 reshape_screens(x, y);
135 void game_keyboard(int key, int pressed)
137 unsigned int mod = game_get_modifiers();
148 game_toggle_fullscreen();
158 screen->keyboard(key, pressed);
161 void game_mouse_button(int bn, int pressed, int x, int y)
163 screen->mouse(bn, pressed, x, y);
166 void game_mouse_motion(int x, int y)
168 screen->motion(x, y);
171 void game_mouse_wheel(int dir)
177 void game_gamepad_axis(int axis, float val)
181 void game_gamepad_button(int bn, int pressed)
185 static void calc_framerate(void)
187 static unsigned long nframes;
188 static long prev_upd;
190 long elapsed = time_msec - prev_upd;
191 if(elapsed >= 1000) {
192 framerate = nframes * 10000 / elapsed;
194 prev_upd = time_msec;
200 static void print_framerate(void)
202 print_text(9 * win_width / 10, 20, 1, 1, 0, "fps: %d.%d", framerate / 10, framerate % 10);