Next: 2.3 Ancillary Buffers Up: 2 OpenGL's Functionality Previous: 2.1 Observations About Primitives

2.2 Two Color Models

OpenGL has two different color modes: RGBA and color index. The glColor3f call has already been demonstrated but not explained. This call assumes OpenGL's RGBA color mode. The routine takes three floating point parameters between 0.0 and 1.0 which specify the degree of red, green, and blue for the current color. For X users, RGBA roughly corresponds to the TrueColor visual type while color index corresponds to PsuedoColor. The color mode is fixed for a given window the same way X windows are created with a single, fixed visual.

You should be able to guess that the RGB in RGBA stands for red, green, and blue. The A may be unfamiliar. It stands for alpha. The alpha value is used when two colors are to be averaged together for blending operations. Alpha represents the opacity of the color. 1.0 is totally opaque while 0.0 is totally transparent. For example, one could use alpha to render a scene with green glass. The frame buffer can support an alpha component which allows alpha values to be stored. Each pixel in the frame buffer would have an associated alpha value. The alpha value is not visible on the display. It is just used to determine how a pixel to be drawn is blended with the current pixel value in the frame buffer. The glAlphaFunc and glBlendFunc routines control precisely how alpha buffering operates. The glColor4f command is a variation on glColor3f which takes a fourth parameter specifying alpha (glColor3f implicitly sets alpha to 1.0).

RGBA supports a tri-linear palette for the full range of colors, making it very useful for rendering realistic scenes. OpenGL supports lighting, fog, and smooth shading most effectively in RGBA mode. Since a lot of hardware has limited color resolution, an application can request OpenGL use dithering for better color resolution (at the expense of spatial resolution).

Many modes in OpenGL, such as dithering, are enabled and disabled using the glEnable and glDisable commands. For example, dithering is enabled by calling glEnable(GL_DITHER). Then drawing would be done with dithering enabled. You can think of glEnable and glDisable as ways to affect the operation of the OpenGL state machine.

The color index model assumes a readable and writable linear colormap. Usually window systems specify how colors are allocated and arranged so OpenGL does not have any specific routines to allocate colors. For example in X, an Xlib color allocation routine such as XAllocColor would be used. The glIndex family of routines is used to set the current color index. The advantage of color index is that the color of a given pixel value can be changed. There is a level of indirection between the pixel values in the frame buffer and the colors on the screen.



Next: 2.3 Ancillary Buffers Up: 2 OpenGL's Functionality Previous: 2.1 Observations About Primitives


mjk@asd.sgi.com
Wed Oct 19 18:06:42 PDT 1994