3 #include <cgmath/cgmath.h>
12 static void calc_framerate(void);
13 static void print_framerate(void);
15 static int should_swap;
16 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);
38 goatvr_set_units_scale(10.0f);
41 should_swap = goatvr_should_swap();
44 glEnable(GL_DEPTH_TEST);
45 glEnable(GL_CULL_FACE);
46 glEnable(GL_LIGHTING);
54 if(opt.flags & OPT_VR) {
60 static void update(float dt)
65 void game_display(void)
67 static long prev_msec;
69 float dt = (float)(time_msec - prev_msec) / 1000.0f;
70 prev_msec = time_msec;
74 if(opt.flags & OPT_VR) {
76 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
82 cgm_mcopy(proj_matrix, goatvr_projection_matrix(i, 0.5, 500.0));
83 glMatrixMode(GL_PROJECTION);
84 glLoadMatrixf(proj_matrix);
86 cgm_mcopy(view_matrix, goatvr_view_matrix(i));
87 glMatrixMode(GL_MODELVIEW);
88 glLoadMatrixf(view_matrix);
103 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
105 cgm_mperspective(proj_matrix, cgm_deg_to_rad(40.0), win_aspect, 0.5, 500.0);
106 glMatrixMode(GL_PROJECTION);
107 glLoadMatrixf(proj_matrix);
109 cgm_midentity(view_matrix);
110 glMatrixMode(GL_MODELVIEW);
111 glLoadMatrixf(view_matrix);
120 assert(glGetError() == GL_NO_ERROR);
125 void game_reshape(int x, int y)
127 glViewport(0, 0, x, y);
128 goatvr_set_fb_size(x, y, 1.0f);
130 reshape_screens(x, y);
133 void game_keyboard(int key, int pressed)
135 unsigned int mod = game_get_modifiers();
146 game_toggle_fullscreen();
152 if(opt.flags & OPT_VR) {
162 screen->keyboard(key, pressed);
165 void game_mouse_button(int bn, int pressed, int x, int y)
167 screen->mouse(bn, pressed, x, y);
170 void game_mouse_motion(int x, int y)
172 screen->motion(x, y);
175 void game_mouse_wheel(int dir)
181 void game_gamepad_axis(int axis, float val)
183 joy_axis[axis] = val;
186 void game_gamepad_button(int bn, int pressed)
189 joy_bnstate |= (1 << bn);
191 joy_bnstate &= ~(1 << bn);
195 static void calc_framerate(void)
197 static unsigned long nframes;
198 static long prev_upd;
200 long elapsed = time_msec - prev_upd;
201 if(elapsed >= 1000) {
202 framerate = nframes * 10000 / elapsed;
204 prev_upd = time_msec;
210 static void print_framerate(void)
212 print_text(9 * win_width / 10, 20, 1, 1, 0, "fps: %d.%d", framerate / 10, framerate % 10);