Introduction to OpenGL

Tom Kelliher, CS 320

Feb. 16, 2000

Administrivia

Announcements

Monday is ``lab day.''

Assignment

Have a look at, and run, viewport.c and paint.c (available on the class home page).

From Last Time

Finished primitive basics.

Outline

  1. Color and color models.

  2. 2-D viewing.

  3. OpenGL control functions.

Coming Up

Viewports, interaction.

Color

Additive color model:

Tristimulus value.

Notes:

  1. Color is continuous.

  2. Our visual system perceives light as a three-color system.

  3. Basic tenet of three-color theory: If two colors produce the same tristimulus values, then they are visually indistinguishable.

  4. Additive: RGB. Subtractive: CMY.

  5. OpenGL has two color modes: RGB and indexed.

RGB Color Mode

  1. Depth of the frame buffer. True color: 24 bits. Number of colors?

  2. We specify a color as a point within the color cube:

    glColor3f(1.0, 0.0, 0.0);
    

  3. Alpha value provides opacity factor:
    glClearColor(1.0, 1.0, 1.0, 1.0);
    

Indexed Color Mode

  1. Many frame buffers have limited depth, say eight bits. However, the graphics controller may be able to display 16M colors.

  2. Suppose: frame buffer has depth k bits. Each color is specified using m bits.

    At any point in time, we should be able to specify any colors from the total collection of colors.

    Use of a color-lookup table:

  3. Shading, for 3-D graphics, requires a large # of colors. So, we'll stick with RGB mode.

Viewing

2-D viewing:

  1. Objects inside the viewing/clipping rectangle are visible:

    What is clipping?

  2. The default viewing volume is and centered at the origin.

The orthographic projection:

  1. Projects the point onto .

  2. In 2-D, we generally want to place objects at z=0.

  3. OpenGL specification:
    void glOrtho(GLdouble left, GLdouble right,
                 GLdouble bottom, GLdouble top,
                 GLdouble near, GLdouble far);
    
    void glOrtho2d(GLdouble left, GLdouble right,
                   GLdouble bottom, GLdouble top);
    
    ``Multiply the current matrix with an orthographic matrix'' --- make the projection matrix the current matrix.

  4. The OpenGL camera defaults to being positioned at the origin, pointed in the -z direction. The camera can ``see'' behind itself.

OpenGL matrices:

  1. Modelview matrix: positions objects in front of the camera.

    Translation, rotation, scaling.

  2. Projection matrix: determines shape of the viewing volume.

    Orthographic, perspective.

Control Functions

Several we've already seen:

  1. glutInit(int *argcp, char *argv[])

  2. glutCreateWindow(char *title)

  3. glutInitDisplayMode(unsigned int mode) Example:
    glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    
    Mode bit examples:
    1. GLUT_RGBA, GLUT_RGB, GLUT_INDEX.

    2. GLUT_SINGLE, GLUT_DOUBLE.

    3. GLUT_DEPTH.



Thomas P. Kelliher
Wed Feb 16 09:35:24 EST 2000
Tom Kelliher