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;
18 int game_init(int argc, char **argv)
20 if(init_opengl() == -1) {
24 if(init_options(argc, argv, "vrtris.conf") == -1) {
28 if(init_screens() == -1) {
32 if(opt.flags & OPT_VR) {
33 if(goatvr_init() == -1) {
36 goatvr_set_origin_mode(GOATVR_HEAD);
39 should_swap = goatvr_should_swap();
42 glEnable(GL_DEPTH_TEST);
43 glEnable(GL_CULL_FACE);
44 glEnable(GL_LIGHTING);
52 if(opt.flags & OPT_VR) {
58 static void update(float dt)
62 if((num_vr_sticks = goatvr_num_sticks()) > 0) {
64 goatvr_stick_pos(0, p);
71 void game_display(void)
73 static long prev_msec;
75 float dt = (float)(time_msec - prev_msec) / 1000.0f;
76 prev_msec = time_msec;
80 if(opt.flags & OPT_VR) {
82 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
88 cgm_mcopy(proj_matrix, goatvr_projection_matrix(i, 0.5, 500.0));
89 glMatrixMode(GL_PROJECTION);
90 glLoadMatrixf(proj_matrix);
92 cgm_mcopy(view_matrix, goatvr_view_matrix(i));
93 glMatrixMode(GL_MODELVIEW);
94 glLoadMatrixf(view_matrix);
109 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
111 cgm_mperspective(proj_matrix, cgm_deg_to_rad(50.0), win_aspect, 0.5, 500.0);
112 glMatrixMode(GL_PROJECTION);
113 glLoadMatrixf(proj_matrix);
115 cgm_midentity(view_matrix);
116 glMatrixMode(GL_MODELVIEW);
117 glLoadMatrixf(view_matrix);
126 assert(glGetError() == GL_NO_ERROR);
131 void game_reshape(int x, int y)
133 glViewport(0, 0, x, y);
134 goatvr_set_fb_size(x, y, 1.0f);
136 reshape_screens(x, y);
139 void game_keyboard(int key, int pressed)
141 unsigned int mod = game_get_modifiers();
152 game_toggle_fullscreen();
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)
185 void game_gamepad_button(int bn, int pressed)
189 static void calc_framerate(void)
191 static unsigned long nframes;
192 static long prev_upd;
194 long elapsed = time_msec - prev_upd;
195 if(elapsed >= 1000) {
196 framerate = nframes * 10000 / elapsed;
198 prev_upd = time_msec;
204 static void print_framerate(void)
206 print_text(9 * win_width / 10, 20, 1, 1, 0, "fps: %d.%d", framerate / 10, framerate % 10);