changeset 9:d325e84a13dd

some cleanups/performance improvements
author jsipek@huey.fsl.cs.sunysb.edu
date Thu, 24 Nov 2005 03:18:55 -0400
parents 640a1d1a730d
children 67d25e36d427
files Makefile render.c
diffstat 2 files changed, 33 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Thu Nov 24 02:18:06 2005 -0400
+++ b/Makefile	Thu Nov 24 03:18:55 2005 -0400
@@ -1,4 +1,4 @@
-all: render transform
+all: render transform rotate
 
 render: render.c
 	gcc render.c -o render -I/usr/X11R6/include/ -L/usr/X11R6/lib -lX11 -lXi -lXmu -lglut -lGL -lGLU -g -Wall -lrt
@@ -10,4 +10,4 @@
 	gcc -o rotate rotate.c -Wall -g -lm
 
 clean:
-	rm -f render transform *~ *.o a.out
+	rm -f rotate render transform *~ *.o a.out
--- a/render.c	Thu Nov 24 02:18:06 2005 -0400
+++ b/render.c	Thu Nov 24 03:18:55 2005 -0400
@@ -70,21 +70,36 @@
 
 void key(unsigned char c, int x, int y)
 {
-	char b[16];
-
 	printf("key pressed: %c, mouse at (%d,%d)\n", c, x, y);
 
-	memset(b, 0, 16);
-	snprintf(b, 16, "%c %d %d\n", c, x, y);
-	write(outfd, b, 16);
+	switch(c) {
+		case GLUT_KEY_LEFT:
+			write(outfd, "left", 4);
+			break;
+		case GLUT_KEY_RIGHT:
+			write(outfd, "right", 5);
+			break;
+		case GLUT_KEY_UP:
+			write(outfd, "up", 2);
+			break;
+		case GLUT_KEY_DOWN:
+			write(outfd, "down", 4);
+			break;
+		case ' ':
+			write(outfd, "space", 5);
+			break;
+		default:
+			write(outfd, &c, 1);
+			break;
+	}
 
 	display();
 }
 
-void timer2(int val)
+void idle()
 {
-	glutPostRedisplay();
-	glutTimerFunc(TIMER_PERIOD, timer2, 0);
+	display();
+	//glutPostRedisplay();
 }
 
 void display(void)
@@ -105,18 +120,20 @@
 		ptr += r;
 	} while(1);
 
-	printf("buf = \"%s\"\n", buf);
-	fflush(stdout);
+	if (strlen(buf)) {
+		printf("buf = \"%s\"\n", buf);
+		fflush(stdout);
+	}
 
 fprintf(stderr,"displaying...%s.\n",buf);
 	if (!strncmp(buf, "CLEAR", 5)) {
-		glClear(GL_COLOR_BUFFER_BIT);
+		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 	} else if (!strncmp(buf, "FLUSH", 5)) {
 		glFlush();
 		glutSwapBuffers();
 	} else if (!strncmp(buf, "POLY", 4))
 		draw_poly(buf);
-	else {
+	else if (strlen(buf)) {
 		printf("unknown command\n");
 		fflush(stdout);
 	}
@@ -195,13 +212,14 @@
 	glutInitWindowSize(800,600);
 	glutInitWindowPosition(0,0);
 	glutCreateWindow("3D Engine");
+	glEnable(GL_DEPTH_TEST);
 	glutDisplayFunc(display);
 	glutKeyboardFunc(key);
 	init();
 	
 	clock_gettime(CLOCK_REALTIME, &start);
 
-	glutTimerFunc(TIMER_PERIOD, timer2, 0);
+	glutIdleFunc(idle);
 	glutMainLoop();