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 int translate_skey(int key);
19 int main(int argc, char **argv)
21 glutInit(&argc, argv);
22 glutInitWindowSize(640, 480);
23 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
24 glutCreateWindow("deeprace");
26 glutDisplayFunc(game_display);
28 glutReshapeFunc(reshape);
29 glutKeyboardFunc(keydown);
30 glutKeyboardUpFunc(keyup);
31 glutSpecialFunc(skeydown);
32 glutSpecialUpFunc(skeyup);
34 glutMotionFunc(motion);
35 glutPassiveMotionFunc(motion);
37 if(game_init() == -1) {
40 atexit(game_shutdown);
45 void game_swap_buffers(void)
48 assert(glGetError() == GL_NO_ERROR);
56 void game_fullscreen(int fs)
58 static int prev_w, prev_h;
65 if(fs == fullscr) return;
68 prev_w = glutGet(GLUT_WINDOW_WIDTH);
69 prev_h = glutGet(GLUT_WINDOW_HEIGHT);
70 prev_grab = mouse_grabbed;
74 glutReshapeWindow(prev_w, prev_h);
82 void game_grabmouse(int grab)
84 static int prev_x, prev_y;
87 grab = !mouse_grabbed;
90 if(grab == mouse_grabbed) return;
96 glutWarpPointer(win_width / 2, win_height / 2);
97 glutSetCursor(GLUT_CURSOR_NONE);
100 glutWarpPointer(prev_x, prev_y);
101 glutSetCursor(GLUT_CURSOR_INHERIT);
103 mouse_grabbed = grab;
107 static void idle(void)
112 static void reshape(int x, int y)
116 glutWarpPointer(x / 2, y / 2);
121 static void keydown(unsigned char key, int x, int y)
123 modkeys = glutGetModifiers();
124 game_keyboard(key, 1);
127 static void keyup(unsigned char key, int x, int y)
129 game_keyboard(key, 0);
132 static void skeydown(int key, int x, int y)
135 modkeys = glutGetModifiers();
136 if((k = translate_skey(key)) >= 0) {
141 static void skeyup(int key, int x, int y)
143 int k = translate_skey(key);
149 static void mouse(int bn, int st, int x, int y)
151 modkeys = glutGetModifiers();
152 game_mouse(bn - GLUT_LEFT_BUTTON, st == GLUT_DOWN, x, y);
155 static void motion(int x, int y)
161 glutWarpPointer(win_width / 2, win_height / 2);
170 static int translate_skey(int key)
181 case GLUT_KEY_PAGE_UP:
183 case GLUT_KEY_PAGE_DOWN:
189 case GLUT_KEY_INSERT:
192 if(key >= GLUT_KEY_F1 && key <= GLUT_KEY_F12) {
193 return key - GLUT_KEY_F1 + GKEY_F1;