/* Paul Solt * A simple setup for the CG2 Ray tracing scene positional values. * 3-20-07 */ #include #include #include GLint width = 500; /* 1.6 aspect ratio */ GLint height = 300; /* Prototypes */ void init(); void display(); void draw(); void timer(); void keyboard( unsigned char key, int x, int y ); void init() { glShadeModel( GL_FLAT ); glClearColor( 0.0, 0.0, 0.0, 1.0 ); } void display() { glClear( GL_COLOR_BUFFER_BIT ); /* Don't need reshape with these function calls */ width = glutGet( GLUT_WINDOW_WIDTH ); height = glutGet( GLUT_WINDOW_HEIGHT ); GLfloat aspectRatio; if( height > 0 ) { /* Make sure it's not minimized */ aspectRatio = (double)width/height; /* Setup the projection and model view matricies */ glViewport( 0, 0, width, height ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluPerspective( 60, aspectRatio, 1.0, 40.0 ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); gluLookAt( 0.0, 1.0, -1.0, 0.0, 0.0, 10.0, 0.0, 1.0, 0.0 ); draw(); glutSwapBuffers(); } } /* Draw the objects */ void draw() { glBegin( GL_QUADS ); { /* Create the floor */ glColor3f( 1.0, 0.0, 0.0 ); glVertex3f( -5.1, 0.0, 10.0 ); glVertex3f( 1.70, 0.0, 10.0 ); glVertex3f( 1.45, 0.0, 0.0 ); glVertex3f( -4.6, 0.0, 0.0 ); } glEnd(); glPushMatrix(); { /* draw the background sphere */ glColor3f( 0.0, 0.8, 6.0 ); glTranslated( -1.3, 0.46, 3.10 ); glutSolidSphere( 1.00, 40, 40 ); } glPopMatrix(); glPushMatrix(); { /* draw the forground sphere */ glColor3f( 0.0, 0.4, 1.0 ); glTranslated( 0.05, 1.08, 0.45 ); glutSolidSphere( 0.50, 40, 40 ); } glPopMatrix(); } /* Redraw the scene every 10 milliseconds */ void timer( int value ) { glutPostRedisplay(); glutTimerFunc( 10, timer, 0 ); } /* Exit when the escape key is pressed */ void keyboard( unsigned char key, int x, int y ) { switch( key ) { case 27: /* Escape key pressed */ exit(1); break; default: break; } } int main( int argc, char *argv[] ) { glutInit( &argc, argv ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); glutInitWindowPosition( 200, 200 ); glutInitWindowSize( width, height ); glutCreateWindow( argv[0] ); init(); glutDisplayFunc( display ); /* call back functions */ glutTimerFunc( 10, timer, 0 ); glutKeyboardFunc( keyboard ); glutMainLoop(); return 0; }