demosys
[andemo] / src / pc / main_glut.c
index cdff0e5..a21cbca 100644 (file)
@@ -7,7 +7,9 @@
 
 static void display(void);
 static void keypress(unsigned char key, int x, int y);
+static void skeypress(int key, int x, int y);
 static void mouse(int bn, int st, int x, int y);
+static int translate_key(int key);
 
 static long start_time;
 
@@ -23,6 +25,7 @@ int main(int argc, char **argv)
        glutIdleFunc(glutPostRedisplay);
        glutReshapeFunc(demo_reshape);
        glutKeyboardFunc(keypress);
+       glutSpecialFunc(skeypress);
        glutMouseFunc(mouse);
        glutMotionFunc(demo_motion);
 
@@ -36,9 +39,14 @@ int main(int argc, char **argv)
        return 0;
 }
 
+void swap_buffers(void)
+{
+       glutSwapBuffers();
+}
+
 static void display(void)
 {
-       demo_time_msec = glutGet(GLUT_ELAPSED_TIME) - start_time;
+       time_msec = glutGet(GLUT_ELAPSED_TIME) - start_time;
 
        demo_display();
 
@@ -53,6 +61,13 @@ static void keypress(unsigned char key, int x, int y)
        demo_keyboard(key, 1);
 }
 
+static void skeypress(int key, int x, int y)
+{
+       if((key = translate_key(key))) {
+               demo_keyboard(key, 1);
+       }
+}
+
 static void mouse(int bn, int st, int x, int y)
 {
        int bidx = bn - GLUT_LEFT_BUTTON;
@@ -60,3 +75,27 @@ static void mouse(int bn, int st, int x, int y)
 
        demo_mouse(bidx, press, x, y);
 }
+
+static int translate_key(int key)
+{
+       if(key >= GLUT_KEY_F1 && key <= GLUT_KEY_F12) {
+               return key - GLUT_KEY_F1 + KEY_F1;
+       }
+       switch(key) {
+       case GLUT_KEY_LEFT:
+               return KEY_LEFT;
+       case GLUT_KEY_RIGHT:
+               return KEY_RIGHT;
+       case GLUT_KEY_UP:
+               return KEY_UP;
+       case GLUT_KEY_DOWN:
+               return KEY_DOWN;
+       case GLUT_KEY_PAGE_UP:
+               return KEY_PGUP;
+       case GLUT_KEY_PAGE_DOWN:
+               return KEY_PGDOWN;
+       default:
+               break;
+       }
+       return 0;
+}