9 int mouse_x, mouse_y, mouse_state[3];
12 int win_width, win_height;
16 struct game_screen *cur_scr;
18 /* available screens */
19 extern struct game_screen scr_menu, scr_game;
21 static struct game_screen *screens[MAX_SCREENS];
22 static int num_screens;
30 /* initialize screens */
31 screens[num_screens++] = &scr_menu;
32 screens[num_screens++] = &scr_game;
34 start_scr_name = getenv("START_SCREEN");
36 for(i=0; i<num_screens; i++) {
37 if(screens[i]->init() == -1) {
40 if(screens[i]->name && start_scr_name && strcmp(screens[i]->name, start_scr_name) == 0) {
41 game_chscr(screens[i]);
45 game_chscr(&scr_game); /* TODO: scr_menu */
50 glClearColor(0.1, 0.1, 0.1, 1);
51 glEnable(GL_DEPTH_TEST);
52 glEnable(GL_CULL_FACE);
53 glEnable(GL_LIGHTING);
58 void game_shutdown(void)
64 for(i=0; i<num_screens; i++) {
65 if(screens[i]->destroy) {
66 screens[i]->destroy();
71 void game_display(void)
73 static long nframes, interv, prev_msec;
76 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
83 msec = glutGet(GLUT_ELAPSED_TIME);
84 interv += msec - prev_msec;
87 float fps = (float)(nframes * 1000) / interv;
88 printf("\rfps: %.2f ", fps);
96 void game_reshape(int x, int y)
100 win_aspect = (float)x / (float)y;
101 glViewport(0, 0, x, y);
103 glMatrixMode(GL_PROJECTION);
105 gluPerspective(50, win_aspect, 0.5, 500);
107 if(cur_scr && cur_scr->reshape) {
108 cur_scr->reshape(x, y);
112 void game_keyboard(int key, int press)
122 if(modkeys & GKEY_MOD_ALT) {
130 if(cur_scr && cur_scr->keyboard) {
131 cur_scr->keyboard(key, press);
135 void game_mouse(int bn, int st, int x, int y)
140 mouse_state[bn] = st;
143 if(cur_scr && cur_scr->mouse) {
144 cur_scr->mouse(bn, st, x, y);
148 void game_motion(int x, int y)
150 if(cur_scr && cur_scr->motion) {
151 cur_scr->motion(x, y);
157 void game_chscr(struct game_screen *scr)
161 if(scr->start && scr->start() == -1) {
165 if(cur_scr && cur_scr->stop) {