7 static void idle(void);
8 static void reshape(int x, int y);
9 static void keydown(unsigned char key, int x, int y);
10 static void keyup(unsigned char key, int x, int y);
11 static void skeydown(int key, int x, int y);
12 static void skeyup(int key, int x, int y);
13 static void mouse(int bn, int st, int x, int y);
14 static void motion(int x, int y);
15 static void sball_motion(int x, int y, int z);
16 static void sball_rotate(int x, int y, int z);
17 static void sball_button(int bn, int st);
18 static int translate_skey(int key);
22 int main(int argc, char **argv)
24 glutInit(&argc, argv);
25 glutInitWindowSize(640, 480);
26 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
27 glutCreateWindow("deeprace");
29 glutDisplayFunc(game_display);
31 glutReshapeFunc(reshape);
32 glutKeyboardFunc(keydown);
33 glutKeyboardUpFunc(keyup);
34 glutSpecialFunc(skeydown);
35 glutSpecialUpFunc(skeyup);
37 glutMotionFunc(motion);
38 glutPassiveMotionFunc(motion);
39 glutSpaceballMotionFunc(sball_motion);
40 glutSpaceballRotateFunc(sball_rotate);
41 glutSpaceballButtonFunc(sball_button);
43 if(game_init() == -1) {
46 atexit(game_shutdown);
51 void game_swap_buffers(void)
54 assert(glGetError() == GL_NO_ERROR);
62 void game_fullscreen(int fs)
64 static int prev_w, prev_h;
71 if(fs == fullscr) return;
74 prev_w = glutGet(GLUT_WINDOW_WIDTH);
75 prev_h = glutGet(GLUT_WINDOW_HEIGHT);
76 prev_grab = mouse_grabbed;
80 glutReshapeWindow(prev_w, prev_h);
88 void game_grabmouse(int grab)
90 static int prev_x, prev_y;
93 grab = !mouse_grabbed;
96 if(grab == mouse_grabbed) return;
102 glutWarpPointer(win_width / 2, win_height / 2);
103 glutSetCursor(GLUT_CURSOR_NONE);
106 glutWarpPointer(prev_x, prev_y);
107 glutSetCursor(GLUT_CURSOR_INHERIT);
109 mouse_grabbed = grab;
113 static void idle(void)
118 static void reshape(int x, int y)
122 glutWarpPointer(x / 2, y / 2);
127 static void keydown(unsigned char key, int x, int y)
129 modkeys = glutGetModifiers();
130 game_keyboard(key, 1);
133 static void keyup(unsigned char key, int x, int y)
135 game_keyboard(key, 0);
138 static void skeydown(int key, int x, int y)
141 modkeys = glutGetModifiers();
142 if((k = translate_skey(key)) >= 0) {
147 static void skeyup(int key, int x, int y)
149 int k = translate_skey(key);
155 static void mouse(int bn, int st, int x, int y)
157 modkeys = glutGetModifiers();
158 game_mouse(bn - GLUT_LEFT_BUTTON, st == GLUT_DOWN, x, y);
161 static void motion(int x, int y)
167 glutWarpPointer(win_width / 2, win_height / 2);
176 static void sball_motion(int x, int y, int z)
180 static void sball_rotate(int x, int y, int z)
184 static void sball_button(int bn, int st)
188 static int translate_skey(int key)
199 case GLUT_KEY_PAGE_UP:
201 case GLUT_KEY_PAGE_DOWN:
207 case GLUT_KEY_INSERT:
210 if(key >= GLUT_KEY_F1 && key <= GLUT_KEY_F12) {
211 return key - GLUT_KEY_F1 + GKEY_F1;