fullscreen and mouse grab
[deeprace] / src / game.c
index e11543f..a747a62 100644 (file)
@@ -1,13 +1,17 @@
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <GL/gl.h>
+#include "miniglut.h"
 #include <GL/glu.h>
 #include "game.h"
 #include "input.h"
 
 int mouse_x, mouse_y, mouse_state[3];
+int mouse_grabbed;
+unsigned int modkeys;
 int win_width, win_height;
 float win_aspect;
+int fullscr;
 
 struct game_screen *cur_scr;
 
@@ -55,6 +59,8 @@ void game_shutdown(void)
 {
        int i;
 
+       putchar('\n');
+
        for(i=0; i<num_screens; i++) {
                if(screens[i]->destroy) {
                        screens[i]->destroy();
@@ -64,11 +70,27 @@ void game_shutdown(void)
 
 void game_display(void)
 {
+       static long nframes, interv, prev_msec;
+       long msec;
+
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
        cur_scr->display();
 
        game_swap_buffers();
+
+
+       msec = glutGet(GLUT_ELAPSED_TIME);
+       interv += msec - prev_msec;
+       prev_msec = msec;
+       if(interv >= 1000) {
+               float fps = (float)(nframes * 1000) / interv;
+               printf("\rfps: %.2f    ", fps);
+               fflush(stdout);
+               nframes = 0;
+               interv = 0;
+       }
+       nframes++;
 }
 
 void game_reshape(int x, int y)
@@ -93,7 +115,15 @@ void game_keyboard(int key, int press)
                switch(key) {
                case 27:
                        game_quit();
-                       break;
+                       return;
+
+               case '\n':
+               case '\r':
+                       if(modkeys & GKEY_MOD_ALT) {
+               case GKEY_F11:
+                               game_fullscreen(-1);
+                       }
+                       return;
                }
        }