Introduction to OpenGL

Tom Kelliher, CS 320

Feb. 11, 2000

Administrivia

Announcements

Assignment

Read 2.5--2.6.

Project due 2/25.

From Last Time

Vertex specification, coordinate systems.

Outline

Coming Up

Viewing and Control.

OpenGL API

Support provided by a graphics API:

  1. Primitive functions: points, line segments, polygons, text, curves, surfaces.

  2. Attribute functions: color, fill, type face.

  3. Viewing functions: attributes of the synthetic camera.

  4. Transformation functions: rotation, translation, scaling. Matrix computations.

  5. Input functions: keyboard, pointing device.

  6. System communication: window system, OS, other workstations, other users.

OpenGL Library Organization:

Primitive Basics

Consider:

glBegin(primitiveType)
   glVertex*( ... );
   // ...
   glVertex*( ... );
glEnd();
for the primitiveTypes:
  1. GL_POINTS .

  2. GL_LINES .

  3. GL_LINE_STRIP .

  4. GL_LINE_LOOP . When is this not a polygon?

Polygon Basics

  1. Polygons have interiors which can be filled.

  2. What is filling? Color, pattern (bitmap) fills.

  3. Simple polygon: no edges cross.

  4. When filling, how do we determine if a point is interior? Crossing test.

  5. Fill example: five-pointed star. Scanlines. Is this the effect we want?

  6. Winding test improvement:
    1. Pick any vertex and direction.

    2. Traverse the polygon, labeling each edge with direction of traversal.

    3. Scanline crosses ``up'' edge: add 1. Crosses ``down'' edge: subtract 1.

    4. Point's winding number starts at 0. In interior if final winding number not 0.

  7. Complications: lines parallel to scanline, intersections with vertices.

  8. Convex and concave polygons.
    1. Definitions.

    2. Concave polygons can present problems.

    3. Often, hardware and software supports triangles.

    4. 2-D polygon convexity test: for any interior point, it is ``to the right'' when traversing the edges clockwise.

  9. OpenGL polygon types: GL_POLYGON, GL_TRIANGLES, GL_QUADS, GL_TRIANGLE_STRIP, GL_QUAD_STRIP, GL_TRIANGLE_FAN.

    What are the strip and fan types?

Text

  1. Stroke text:
    1. Specified by vertices.

    2. Can send it through the graphics pipeline to manipulate it (point size, italics face).

    3. Computational-, storage-expensive

    4. Example: Postscript.

  2. Raster text:
    1. Specified by a bit-map.

    2. A font is often stored as a strip. Individual characters are copied to the frame buffer via bitblt operations.

    3. Can't process through the graphics pipeline. Changing the point size by changing the pixel size: blockiness. Or by using several ``strips.''

    4. Computational-, storage-inexpensive.

General Curved Surfaces

Tessellation: Mesh of convex polygons. 2-D, 3-D.

Example: circle formed by GL_TRIANGLE_FAN.

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.



Thomas P. Kelliher
Thu Feb 10 21:43:14 EST 2000
Tom Kelliher