Polygons, Windows, and Viewing

Tom Kelliher, CS 320

Feb. 4, 1998

Announcements:

From last time:

  1. Intro. to OpenGL.

  2. Basic graphics primitives: points, line segments.

  3. Properties of polygons.

Outline:

  1. Polygons.

  2. Setting up a window and establishing world and device mappings.

Assignment: Handout.

Polygons

Polygon types:

  1. GL_POLYGON

  2. GL_TRIANGLES, GL_QUADS .

  3. GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_QUAD_STRIP .

Windows and Viewing

Here's the window creating and model viewing code from the Sierpinski gasket:

glutInit(&argc,argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow("Sierpinski Gasket");

glutIdleFunc (display);
glutMouseFunc (mouse);  
glClearColor(1.0, 1.0, 1.0, 0.0); /* white background */
glColor3f(1.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 500.0, 0.0, 500.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glutDisplayFunc(clear);

glutMainLoop();

Description:

  1. glutInit(int *argc,char **argv): Initializes GLUT library, parses any GLUT command line arguments.

  2. glutInitDisplayMode(unsigned int mode): Selects single-buffered, RGB color. Some mode possibilities: Note the OR mask.

  3. glutInitWindowSize(int width, int height): Requested width and height, in pixels, of window.

  4. glutInitWindowPosition(int x, int y): Requested initial position of window.

  5. int glutCreateWindow(char *name): Create the window using the given name. Value returned is window ID.

  6. glutIdleFunc(void (*func)(void)): Function which will run when window system events (redraw, input, etc.) aren't being handled.

  7. glutMouseFunc(void (*func)(int button, int state, int x, int y): Set the mouse callback function.

  8. glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha): Specify clear values for the color buffers.

  9. glColor3f(GLfloat red, GLfloat green, GLfloat blue): Set the current color.

  10. glMatrixMode(GLenum mode): Specify which matrix is current. Some possibilities:
    1. GL_MODELVIEW : this matrix is used to position the camera.

    2. GL_PROJECTION : this matrix is used to select the projection volume: clipping and depth of field.

  11. glLoadIdentity(void): Replace the current matrix with the identity matrix.

  12. glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top,
    GLdouble zNear, GLdouble zFar): Multiply the current matrix with an orthographic matrix. This produces a clipped, parallel projection.

  13. glutDisplayFunc(void (*func)(void)): Sets the re-display callback.

  14. glutMainLoop(void): Run the event processing loop, calling registered callbacks as necessary.

Don't forget the man pages and how to ``project'' the function names.



Thomas P. Kelliher
Tue Feb 3 09:27:48 EST 1998
Tom Kelliher