9 int mouse_x, mouse_y, mouse_state[3];
10 int win_width, win_height;
13 struct game_screen *cur_scr;
15 /* available screens */
16 extern struct game_screen scr_menu, scr_game;
18 static struct game_screen *screens[MAX_SCREENS];
19 static int num_screens;
27 /* initialize screens */
28 screens[num_screens++] = &scr_menu;
29 screens[num_screens++] = &scr_game;
31 start_scr_name = getenv("START_SCREEN");
33 for(i=0; i<num_screens; i++) {
34 if(screens[i]->init() == -1) {
37 if(screens[i]->name && start_scr_name && strcmp(screens[i]->name, start_scr_name) == 0) {
38 game_chscr(screens[i]);
42 game_chscr(&scr_game); /* TODO: scr_menu */
47 glClearColor(0.1, 0.1, 0.1, 1);
48 glEnable(GL_DEPTH_TEST);
49 glEnable(GL_CULL_FACE);
50 glEnable(GL_LIGHTING);
55 void game_shutdown(void)
61 for(i=0; i<num_screens; i++) {
62 if(screens[i]->destroy) {
63 screens[i]->destroy();
68 void game_display(void)
70 static long nframes, interv, prev_msec;
73 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
80 msec = glutGet(GLUT_ELAPSED_TIME);
81 interv += msec - prev_msec;
84 float fps = (float)(nframes * 1000) / interv;
85 printf("\rfps: %.2f ", fps);
93 void game_reshape(int x, int y)
97 win_aspect = (float)x / (float)y;
98 glViewport(0, 0, x, y);
100 glMatrixMode(GL_PROJECTION);
102 gluPerspective(50, win_aspect, 0.5, 500);
104 if(cur_scr && cur_scr->reshape) {
105 cur_scr->reshape(x, y);
109 void game_keyboard(int key, int press)
119 if(cur_scr && cur_scr->keyboard) {
120 cur_scr->keyboard(key, press);
124 void game_mouse(int bn, int st, int x, int y)
129 mouse_state[bn] = st;
132 if(cur_scr && cur_scr->mouse) {
133 cur_scr->mouse(bn, st, x, y);
137 void game_motion(int x, int y)
139 if(cur_scr && cur_scr->motion) {
140 cur_scr->motion(x, y);
146 void game_chscr(struct game_screen *scr)
150 if(scr->start && scr->start() == -1) {
154 if(cur_scr && cur_scr->stop) {