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);
37 goatvr_set_units_scale(10.0f);
40 should_swap = goatvr_should_swap();
43 glEnable(GL_DEPTH_TEST);
44 glEnable(GL_CULL_FACE);
45 glEnable(GL_LIGHTING);
53 if(opt.flags & OPT_VR) {
59 static void update(float dt)
63 if((num_vr_sticks = goatvr_num_sticks()) > 0) {
65 goatvr_stick_pos(0, p);
72 void game_display(void)
74 static long prev_msec;
76 float dt = (float)(time_msec - prev_msec) / 1000.0f;
77 prev_msec = time_msec;
81 if(opt.flags & OPT_VR) {
83 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
89 cgm_mcopy(proj_matrix, goatvr_projection_matrix(i, 0.5, 500.0));
90 glMatrixMode(GL_PROJECTION);
91 glLoadMatrixf(proj_matrix);
93 cgm_mcopy(view_matrix, goatvr_view_matrix(i));
94 glMatrixMode(GL_MODELVIEW);
95 glLoadMatrixf(view_matrix);
110 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
112 cgm_mperspective(proj_matrix, cgm_deg_to_rad(40.0), win_aspect, 0.5, 500.0);
113 glMatrixMode(GL_PROJECTION);
114 glLoadMatrixf(proj_matrix);
116 cgm_midentity(view_matrix);
117 glMatrixMode(GL_MODELVIEW);
118 glLoadMatrixf(view_matrix);
127 assert(glGetError() == GL_NO_ERROR);
132 void game_reshape(int x, int y)
134 glViewport(0, 0, x, y);
135 goatvr_set_fb_size(x, y, 1.0f);
137 reshape_screens(x, y);
140 void game_keyboard(int key, int pressed)
142 unsigned int mod = game_get_modifiers();
153 game_toggle_fullscreen();
159 if(opt.flags & OPT_VR) {
169 screen->keyboard(key, pressed);
172 void game_mouse_button(int bn, int pressed, int x, int y)
174 screen->mouse(bn, pressed, x, y);
177 void game_mouse_motion(int x, int y)
179 screen->motion(x, y);
182 void game_mouse_wheel(int dir)
188 void game_gamepad_axis(int axis, float val)
192 void game_gamepad_button(int bn, int pressed)
196 static void calc_framerate(void)
198 static unsigned long nframes;
199 static long prev_upd;
201 long elapsed = time_msec - prev_upd;
202 if(elapsed >= 1000) {
203 framerate = nframes * 10000 / elapsed;
205 prev_upd = time_msec;
211 static void print_framerate(void)
213 print_text(9 * win_width / 10, 20, 1, 1, 0, "fps: %d.%d", framerate / 10, framerate % 10);