/* File: step1.c Author: Katia Oleinik This example demonstrates - viewing clipping planes - perspective (glFrustum) and orthographic (glOrtho) views - setting up camera position - RGB colors - GLUT primitieves Solution to the Assignment: 1. Draw a ball of radius 1, with the color of your choice 2. Set ortho proj., so that the diam. of the ball would be about 20% of the width of the screen. 3. Set camera on z axis 5 units away from the origin */ #include #include #include void mydraw(void); void display(void); void init(void); /* drawing routine, called by display every animated frame */ void mydraw(void) { /* Set up red color */ glColor3f( 1.0, 0.0, 0.0); // red color /* draw a sphere of radius 1.*/ glutSolidSphere(1., 24, 24); } /* display is called by the glut main loop once for every animated frame */ void display(void) { /* initialize color and depth buffers */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* call the routine that actually draws what you want */ mydraw(); /* show the just-filled frame buffer */ glutSwapBuffers(); } /* called once to set up basic opengl state */ void init(void) { /* Use depth buffering for hidden surface elimination. */ glEnable(GL_DEPTH_TEST); /* Set up the perspective matrix */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); /* left, right, bottom, top, near, far */ /* near and far values are the distances from the camera to the front and rear clipping planes */ glOrtho(-4.0, 4.0, -4.0, 4.0, 1., 10.0); // orthgraphic view /* Set up the model view matrix */ glMatrixMode(GL_MODELVIEW); glLoadIdentity(); /* Camera position */ /* By the default, the camera is situated at the origin, points down the negative z-axis, and has an upper vector (0,1,0)*/ gluLookAt(0.,0.,5.,0.,0.,0.,0.,1.,0.); } int main(int argc, char **argv) { /* GLUT Configuration */ glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); /* These setup calls are optional - set size and position of the window */ glutInitWindowSize(500,500); glutInitWindowPosition(100,100); /* Create Window */ glutCreateWindow("Red ball"); /* Set display as a callback for the current window */ glutDisplayFunc(display); /* Set basic openGL states */ init(); /* Enter GLUT event processing loop, which interprets events and calls respective callback routines */ glutMainLoop(); /* Exit the program */ return 0; }