/* This shows reading from terminal with the graphics window on. This is done by registering a callback on IdleFunc, called linein(). This is a function that waits for the user to type in a line, then does some dummy printing with it. Reading the line from the user is done with asyncGetLine(), which is defined in io.c, which starts another thread that waits for the user. Just check it out -- its worth a thousand words. Laura Toma csci350 */ #include #include #include #include #ifdef __APPLE__ #include #else #include #endif GLfloat blue[3] = {0.0, 0.0, 1.0}; GLfloat white[3] = {1.0, 1.0, 1.0}; GLfloat gray[3] = {0.5, 0.5, 0.5}; /* forward declarations of functions */ void display(void); void keypress(unsigned char key, int x, int y); #include "io.h" void linein() { char buf[BUFSIZ]; int n; n = asyncGetLine(buf, BUFSIZ); if(n > 0) { fprintf(stderr, "I got a line: %s\n", buf); fprintf(stderr, "calling keypress(%c)\n", buf[0]); keypress(buf[0], 0, 0); } if(n < 0) { exit(0); } } int main(int argc, char** argv) { /* open a window */ glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(500, 500); glutInitWindowPosition(100,100); glutCreateWindow(argv[0]); /* OpenGL init */ glClearColor(0, 0, 0, 0); /* set background color black*/ glClear(GL_COLOR_BUFFER_BIT); /* clear background color */ /* glOrtho(-1,1,-1,1,-1,1); */ /* set projection */ glColor3f(1.0,1.0,1.0); /* set draw color white */ /* glColor3fv(blue); */ /* set draw color blue */ /* glColor3fv(gray); */ /* set draw color gray */ /* keep window on the screen */ glutDisplayFunc(display); /* attach keyboard event handling */ glutKeyboardFunc(keypress); glutIdleFunc(linein); glutMainLoop(); return 0; } void display(void) { /* draw a polygon */ glBegin(GL_POLYGON); glVertex2f(-0.5,-0.5); glVertex2f(-0.5,0.5); glVertex2f(0.5,0.5); glVertex2f(0.5,-0.5); glEnd(); /* execute the drawing commands */ glFlush(); } void keypress(unsigned char key, int x, int y) { switch(key) { case 'q': exit(0); break; } }