3 #include <cgmath/cgmath.h>
10 static void calc_framerate(void);
11 static void print_framerate(void);
13 static float view_matrix[16], proj_matrix[16];
14 static int should_swap;
15 static unsigned long framerate;
17 int game_init(int argc, char **argv)
19 if(init_opengl() == -1) {
23 if(init_options(argc, argv, "vrtris.conf") == -1) {
27 if(init_screens() == -1) {
31 if(opt.flags & OPT_VR) {
32 if(goatvr_init() == -1) {
35 goatvr_set_origin_mode(GOATVR_HEAD);
38 should_swap = goatvr_should_swap();
45 if(opt.flags & OPT_VR) {
51 static void update(float dt)
55 if((num_vr_sticks = goatvr_num_sticks()) > 0) {
57 goatvr_stick_pos(0, p);
64 void game_display(void)
66 static long prev_msec;
68 float dt = (float)(time_msec - prev_msec) / 1000.0f;
69 prev_msec = time_msec;
73 if(opt.flags & OPT_VR) {
75 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
81 cgm_mcopy(proj_matrix, goatvr_projection_matrix(i, 0.5, 500.0));
82 glMatrixMode(GL_PROJECTION);
83 glLoadMatrixf(proj_matrix);
85 cgm_mcopy(view_matrix, goatvr_view_matrix(i));
86 glMatrixMode(GL_MODELVIEW);
87 glLoadMatrixf(view_matrix);
102 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
104 cgm_mperspective(proj_matrix, cgm_deg_to_rad(50.0), win_aspect, 0.5, 500.0);
105 glMatrixMode(GL_PROJECTION);
106 glLoadMatrixf(proj_matrix);
108 cgm_midentity(view_matrix);
109 glMatrixMode(GL_MODELVIEW);
110 glLoadMatrixf(view_matrix);
119 assert(glGetError() == GL_NO_ERROR);
124 void game_reshape(int x, int y)
126 glViewport(0, 0, x, y);
127 goatvr_set_fb_size(x, y, 1.0f);
129 reshape_screens(x, y);
132 void game_keyboard(int key, int pressed)
134 unsigned int mod = game_get_modifiers();
145 game_toggle_fullscreen();
155 screen->keyboard(key, pressed);
158 void game_mouse_button(int bn, int pressed, int x, int y)
160 screen->mouse(bn, pressed, x, y);
163 void game_mouse_motion(int x, int y)
165 screen->motion(x, y);
168 void game_mouse_wheel(int dir)
174 void game_gamepad_axis(int axis, float val)
178 void game_gamepad_button(int bn, int pressed)
182 static void calc_framerate(void)
184 static unsigned long nframes;
185 static long prev_upd;
187 long elapsed = time_msec - prev_upd;
188 if(elapsed >= 1000) {
189 framerate = nframes * 10000 / elapsed;
191 prev_upd = time_msec;
197 static void print_framerate(void)
199 print_text(9 * win_width / 10, 20, 1, 1, 0, "fps: %d.%d", framerate / 10, framerate % 10);