[ Previous | Next | Contents | Glossary | Home | Search ]
GL3.2 Version 4.1 for AIX: Programming Concepts

Working in Color Map and RGB Modes

This section contains discussions on the following topics:

The creation of graphics includes two basic steps: first, the drawing subroutines write data into the bitplanes, and second, the display hardware interprets that data as colors on the screen. The GL subroutines control both the patterns of zeros and ones that are written into the bitplanes of each pixel and the interpretation of those patterns as colors on the screen.

List of GL Color Map and RGB Mode Subroutines

cmode
                          Sets color map mode as the current mode.
gammaramp
                          Defines a color map ramp for gamma correction.
getcmmode
                          Returns the organization of the current color map.
getmap
                          Returns the number of the current color map.
getmcolor
                          Gets a copy of the RGB values for a color map entry.
getmcolors
                          Returns a range of color map RGB values.
mapcolor
                          Changes a color map entry to a specified RGB value.
mapcolors
                          Loads a range of color map entries.
multimap
                          Organizes the color map as 16 small maps.
onemap
                          Organizes the color map as one large map.
RGBmode
                          Sets a display mode that bypasses the color map.
setmap
                          Selects one of 16 small color maps.

Color Display

If you have a standard monitor, it has three color guns that sweep the entire screen area 60 times per second. During this sweep, each gun points directly at each of the pixels for a very short time. The color guns shoot out electrons that strike the screen and cause it to glow.

Each pixel on the screen is composed of three different phosphors that glow red, green, or blue. One color gun activates only the red phosphors, one only the green, and the other only the blue. As each color gun sweeps across the pixels, the number of electrons shot out (the intensity) is modified on a pixel-to-pixel basis.

Consider just the red color gun. If no electrons are fired at a pixel, its phosphors do not glow at all, and it appears black. If the gun is turned on to its highest intensity, the phosphor glows bright red. At intermediate intensities, the colors vary between black to bright red.

The same is true for the other guns, except that the colors vary from black to bright green, or from black to bright blue. The color your eye perceives for a pixel is the combination of all three colors. Different combinations of intensity settings of the guns cause a wide variety of colors to appear.

Each color gun can be set to 256 different intensity levels, ranging from completely off to completely on. Setting 0 is completely off and setting 255 is completely on. The intensities of the red, green, and blue guns at the pixel determine its color. This is expressed as an RGB triple: three numbers between 0 and 255 indicating the red, green, and blue intensity, in that order.

For example, black is represented by (0,0,0), bright red by (255,0,0), and bright green by (0,255,0). Other examples include: (255,255,0) = yellow, (0,255,255) = cyan, (255,0,255) = magenta, (255,255,255) = white. The colors represented by black = (0,0,0), (1,1,1), (2,2,2), and so on through (255,255,255) = white are different shades of gray ranging from black to white. Because each gun has 256 different settings, there are 16777216 (256x256x256) different colors available.

RGB Mode

The simplest way to interpret pixel data is to provide 8 bits each (255 values) for red, green, and blue, then display exactly those values of red, green, and blue on the screen. This is called RGB mode and requires 24 bits of data per pixel.

Hardware for RGB mode can be built easily if there are 24 bitplanes available. Each one of the three groups of eight bitplanes can be used to store one of the RGB components. Each component is then fed via the digital-to-analog converters (DAC) to the electron guns of the monitor.

Through a technique called dithering, RGB mode is also available on adapters with fewer than 24 bitplanes; in particular, the 8-bitplane systems. Because the 256 colors available on a 8-bitplane system are not enough to create full-color images if employed in the most straightforward fashion, another technique, such as dithering, is required to achieve full color realism.

Dithering is similar to the process used by magazines to print full-color photographs with a base of only four colors. To replicate a color that is not in the palette of 256, alternating pixels in the frame buffer are set to either one of the two or more nearest available colors. This creates a faint and very fine checkerboard pattern that, when viewed from a distance, appears to be the desired color. The success of this technique depends on the fact that the pixels are imperceptible at normal viewing distances.

Color Map Mode

Another way to write and interpret the data in the bitplanes is color map mode. Many applications are better suited to color map mode than to RGB mode. Many of the principles of color maps are used in the overlay, underlay, and pop-up menu modes.

Color map mode is useful for representing scalar false color data, such as temperatures, pressures, viscosities, strains, elevations, and material compositions. It also provides a convenient way to achieve blinking or other simple animation. This technique, called color map animation, makes predrawn images appear to move by simply changing the color map.

Color map mode provides a level of indirection between the values stored in the bitplanes and the RGB values displayed on the screen. The value stored in the standard bitplanes (up to 12 bits) is interpreted as an index into a color map. Each entry in the color map consists of a full 8 bits each of red, green, and blue intensity. To specify a color for a pixel on the screen, set the corresponding bit in each of the 12 bitplanes to represent a number between 0 and 4095. This number specifies an index into the color map that indicates the red, green, and blue value for that pixel.

Because the system is in color map mode by default, the lowest 8 values in the color map are loaded as follows:

The Lowest 8 Color Map Values
Red Green Blue Color
0 0 0 BLACK
255 0 0 RED
0 255 0 GREEN
255 255 0 YELLOW
0 0 255 BLUE
255 0 255 MAGENTA
0 255 255 CYAN
255 255 255 WHITE

In the default color map mode, therefore, an index value of 0 for a given pixel causes that pixel to be displayed as black.

Virtualization of Colormaps

The X server treats colormaps as a shared resource, that is, colormaps are virtualized by the X server. Every X client can, but does not have to, request a colormap that is unique to itself and is different from those of the other clients. Under certain circumstances (usually when the client has "focus"), the colormap for that client is loaded into the physical hardware colormap. In such a case, the colors for the given window for the given client appear correct; the colors of the other windows (possibly including the root window) may appear incorrect, if the colormaps of the other windows are different than the currently loaded colormap. The X server does not set the policy for when a given colormap is loaded; this is done by the window manager. Additional information about colormaps and colormap focus policies can be found in the X and Motif documentation.

Note: Some graphics adapters have more physical hardware colormaps than others. In particular, the 24-bit POWERgraphics GTO, POWER Gt4 and POWER Gt4x adapters have five hardware colormaps each. The X server, in concert with the window manager, is able to manage all five colormaps. If all the clients running on the screen request more than five different colormaps, at least some of the clients will have the incorrect colormap installed. This affects the management of colormaps.

GL Colormaps

The GL paradigm for colormaps is that of a single, hardware colormap. Historically, the GL applications programming interface (API) did not virtualize colormaps; it simply provided access to a single hardware colormap. In the integration of GL with X windows, this behavior is emulated with special code. Thus, the mapcolor and mapcolors subroutines set a single colormap kept within the X server. A change to this colormap by one GL application affects not only all windows of that application, but all GL applications. Thus, GL applications must cooperate in the sharing of this colormap to obtain high quality visual results.

Using X11 Colormaps with GL

GL supports the use of X11 colormap management subroutines to set and change the colormap(s) associated with a GL window. If the X11 colormap routines are not used, GL creates a single instance of a colormap and associates it with each GL window that is created. This single colormap is accessed with the mapcolor and mapcolors subroutines. Use of this default colormap can be side-stepped by using the X Window System to create a separate colormap, and associate it to a GL window.

If X11 is used to manage the colormaps for GL windows, then X11 must also be used to allocate the entries in the colormap. The mapcolor and mapcolors subroutines can be used to change the colors only in the default, private GL map and not in any separately created colormaps.

An example showing how X11 colormap facilities can be used with GL is found in /usr/lpp/GL/examples/Xcolormap.c.

Note: On the POWERgraphics GXT1000, be sure that the correct X11 window ID has been obtained. Note the GXT1000-specific information in the getXdpy subroutine.

Onemap and Multimap Modes

When you are in color map mode and in the default onemap mode, the value of the color bitplanes is used as an index into the color map to determine the color displayed on the screen. In onemap mode, the lowest order 12 bits in the frame buffer are used to index into a 4096-entry color map.

In multimap mode, the setmap subroutine makes one of the 16 small color maps current. All display is done using the current small map, and the mapcolor subroutine affects that map.

Call the gconfig subroutine to activate the onemap or multimap settings.

Subroutines you use with the onemap subroutine and multimap subroutine are: the getcmmode subroutine, which returns the organization of the current color map; the setmap subroutine, which selects which of the small maps the system uses in multimap mode; the getmap subroutine, which returns the number of the current color map; and the cyclemap subroutine, which cycles through the color maps at a selected rate.

multimap Subroutine

The multimap subroutine organizes the color map as 16 small maps, each with a maximum of 256 RGB entries. The multimap subroutine does not take effect until the gconfig subroutine is called. The syntax is as follows:

void multimap()

onemap Subroutine

The onemap subroutine organizes the color map as a single map with 4096 entries. You must call the gconfig subroutine for the onemap subroutine to take effect. Onemap is the default mode. The syntax is as follows:

void onemap()

getcmmode Subroutine

The getcmmode subroutine returns the organization of the current color map. A return value of FALSE indicates multimap mode, and TRUE indicates onemap mode. The syntax is as follows:

Int32 getcmmode()

setmap Subroutine

The setmap subroutine selects which of the small maps (0 through 15) the system uses in multimap mode. This selection is ignored in onemap mode. The syntax is as follows:

void setmap(Int16 mapnum)

getmap Subroutine

The getmap subroutine returns the number (from 0 to 15) of the current color map. In onemap mode, this subroutine always returns 0. The syntax is as follows:

Int32 getmap()

cyclemap Subroutine

The cyclemap subroutine cycles through color maps at a specified rate. It defines a duration (in vertical retraces, the current map, and the map that follows when the duration lapses. For example, the following routines set up multimap mode and cycle between two maps, leaving map 1 on for 10 vertical retraces and map 3 on for 5 retraces:

multimap();
gconfig();
cyclemap(10, 1, 3);
cyclemap(5, 3, 1);

When you kill a window or attach to a new window, the maps stop cycling. The syntax is as follows:

void cyclemap(Int16 duration, Int16 map, Int16 nextmap)

Gamma Correction

The light output of any video display is controlled by the input voltage to the monitor. The relationship between input voltage and the brightness of the display, however, is not linear. For instance, assume that 100% of a monitor's input voltage produces 100% brightness. If you reduce the voltage to 50% of its initial value, the monitor might display only 19% of its initial brightness.

To achieve a linear response from the monitor, the system must vary the input voltage by some exponent. The exponent is called the monitor's gamma. Linear response is achieved on standard monitors with a gamma of 2.4. The system uses a hardware lookup table to compensate for nonlinear response.

Note: Some graphics adapters have more physical hardware colormaps than others. In particular, the 24-bit POWERgraphics GTO, POWER Gt4 and POWER Gt4x adapters have five hardware colormaps each. The X server, in concert with the window manager, is able to manage all five. Note that if all the clients running on the screen request more than five different colormaps, at least some of the clients will have the incorrect colormap installed. This affects the management of gamma ramps.

GL Gamma Ramps

The historical GL paradigm for gamma ramps has been that of a single, hardware gamma ramp that affected the entire screen. The gammaramp subroutine can be used to load that lookup table. This is the case on the 3D Color Graphics Processor adapter; the X server is ignorant of this particular lookup table and does not manage it.

With the newer adapters, the POWERgraphics GTO, the POWER Gt4 and the POWER Gt4x, this paradigm has been modified. When in RGB mode, the gamma ramp for any particular window can be set independently of any other window. Note that the gamma ramps for these adapters are realized as X colormaps. Thus, the X server engages in the management of the RGB mode gamma ramps, and all of the usual rules and behaviors with regard to X colormap management apply. Note, in particular, that a GL RGB window may appear incorrect if the X server hasn't installed a linear ramp. Note also that if more than five different gamma ramps are created, not all can be installed simultaneously, and some RGB windows may appear with incorrect colors.

gammaramp Subroutine

The gammaramp subroutine supplies another level of indirection for all color map and RGB values. It affects only the display of color, not the values that are written in the bitplanes. Use the gammaramp subroutine to provide gamma correction, to equalize monitors with different color characteristics, or to modify the color warmth of the monitor.

The gammaramp subroutine affects the entire screen and all running processes. It stays in effect until another call to the same subroutine is made or until the graphics hardware is reset. The default setting has r[i]=g[i]=b[i]=i (no modification).

When objects are drawn on the screen in RGB mode, red, green, and blue are stored in the bitplanes, displayed as (red, green, blue), and are the arrays last specified by the gammaramp subroutine. Similarly, in color map mode if color i is mapped to red, green, blue, objects written in color i are displayed as (red, green, blue). The syntax is as follows:

void gammaramp(Int16 red[256], Int16 green[256], Int16 blue[256])

You may want to read how the different color modes are used in "Creating Animated Scenes", "Creating Lighting Effects", "Performing Depth-Cueing", and "Removing Hidden Surfaces".


[ Previous | Next | Contents | Glossary | Home | Search ]