changeset 11:55b7e6aba0ef

Fixed key scan code bug Switched back to timer-model; idle loop was just killing the CPU, and not getting enough things done Changed the window resolutions to 800x800
author jsipek@huey.fsl.cs.sunysb.edu
date Thu, 24 Nov 2005 03:59:14 -0400
parents 67d25e36d427
children 43c7ce2fc334
files render.c
diffstat 1 files changed, 22 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/render.c	Thu Nov 24 03:57:33 2005 -0400
+++ b/render.c	Thu Nov 24 03:59:14 2005 -0400
@@ -68,21 +68,21 @@
 	glEnd();
 }
 
-void key(unsigned char c, int x, int y)
+void __key(int c, int x, int y)
 {
 	printf("key pressed: %c, mouse at (%d,%d)\n", c, x, y);
 
 	switch(c) {
-		case GLUT_KEY_LEFT:
+		case GLUT_KEY_LEFT+256:
 			write(outfd, "left", 4);
 			break;
-		case GLUT_KEY_RIGHT:
+		case GLUT_KEY_RIGHT+256:
 			write(outfd, "right", 5);
 			break;
-		case GLUT_KEY_UP:
+		case GLUT_KEY_UP+256:
 			write(outfd, "up", 2);
 			break;
-		case GLUT_KEY_DOWN:
+		case GLUT_KEY_DOWN+256:
 			write(outfd, "down", 4);
 			break;
 		case ' ':
@@ -92,14 +92,23 @@
 			write(outfd, &c, 1);
 			break;
 	}
+	write(outfd, "\n", 1);
+}
 
-	display();
+void key(unsigned char c, int x, int y)
+{
+	__key((int)c, x, y);
 }
 
-void idle()
+void special(int k, int x, int y)
 {
-	display();
-	//glutPostRedisplay();
+	__key(k+256, x, y);
+}
+
+void timer(int val)
+{
+	glutPostRedisplay();
+	glutTimerFunc(TIMER_PERIOD, timer, 0);
 }
 
 void display(void)
@@ -209,17 +218,19 @@
 
 	glutInit(&argc,argv);
 	glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
-	glutInitWindowSize(800,600);
+	glutInitWindowSize(800,800);
 	glutInitWindowPosition(0,0);
 	glutCreateWindow("3D Engine");
 	glEnable(GL_DEPTH_TEST);
 	glutDisplayFunc(display);
 	glutKeyboardFunc(key);
+	glutSpecialFunc(special);
 	init();
 	
 	clock_gettime(CLOCK_REALTIME, &start);
 
-	glutIdleFunc(idle);
+	//glutIdleFunc(idle);
+	glutTimerFunc(TIMER_PERIOD, timer, 0);
 	glutMainLoop();