/* 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 Assignment: 1. Draw a ball with the color of your choice 2. Set orthographic proj., so that the diam. of the ball would be about 20% of the width of the screen. 3. Set up camera on z axis 5 units away from the origin */ #include #include #include /* user defined functions declarations */ void mydraw(void); void display(void); void init(void); /* drawing routine, called by display every animated frame */ void mydraw(void) { /* Set up the color */ /* RGB values range from 0.0 to 1.0 */ glColor3f( 1.0, 0.0, 0.0); // red color //glColor3f( 0.0, 1.0, 0.0); // green color /* draw a teapot */ glutSolidTeapot(.5); //or glutWireTeapot(.5) /* try different GLUT primitieves */ /* Sphere, Cube, Cone, Torus, etc. */ } /* 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(); /* update the 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 */ glFrustum(-1.0, 1.0, -1.0, 1.0, 1., 10.0); // perspective view //glOrtho(-1.0, 1.0, -1.0, 1.0, 1., 10.0); // orthgraphic view /* Another way to define perspective viewing volume fovy, aspect, near, far */ //gluPerspective(45.0f, 1., 1., 10.); /* 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.,2.,0.,0.,0.,0.,1.,0.); //gluLookAt(1.,1.,1.,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("GL Teapot"); /* Set display as a callback for the current window */ glutDisplayFunc(display); /* Set basic openGL states */ init(); /* Enter GLUT event processing loop */ glutMainLoop(); /* Exit the program */ return 0; }