hide random home http://www.sgi.com/tech/openGL/mjk.xlib/subsubsection3_2_1_1.html (Silicon Surf Promotional CD, 01/1995)



Next: 2.1.2 Creating a Rendering Up: 2.1 Initialization Previous: 2.1 Initialization

2.1.1 Choosing a Visual and Colormap

The GLX extension overloads X visuals to denote supported frame buffer configurations. Before you create an OpenGL window, you should select a visual which supports the frame buffer features you intend to use. GLX guarantees at least two visual will be supported. An RGBA mode visual with a depth buffer, stencil buffer, and accumulation buffer must be supported. Second, a color index mode visual with a depth buffer and stencil buffer must be available. More and less capable visuals are likely to also be supported depending on the implementation.

To make it easy to select a visual, glXChooseVisual takes a list of the capabilities you are requesting and returns an XVisualInfo* for a visual meeting your requirements. NULL is returned if a visual meeting your needs is not available. To ensure your application will run with any OpenGL GLX server, your program should be written to support the base line required GLX visuals. Also you should only ask for the minimum set of frame buffer capabilities you require. For example, if your program never uses a stencil buffer, you will possibly waste resources if you request one anyway.

Since glxdino rotates the dinosaur in response to user input, the program will run better if double buffering is available. Double buffering allows a scene to be rendered out of view and then displayed nearly instantly to eliminate the visual artifacts associated with watching a 3D scene render. Double buffering helps create the illusion of smooth animation. Since double buffering support is not required for OpenGL implementations, glxdino resorts to single buffering if no double buffer visuals are available. The program's configuration integer array tells what capabilities glXChooseVisual should look for. Notice how if a double buffer visual is not found, another attempt is made which does not request double buffering by starting after the GLX_DOUBLBUFFER token. And when the -single option is specified, the code only looks for a singled buffered visual.

glxdino does require a depth buffer (of at least 16 bits of accuracy) and uses the RGBA color model. The RGBA base line visual must support at least a 16 bit depth buffer so glxdino should always find a usable visual.

You should not assume the visual you need is the default visual. Using a non-default visual means windows created using the visual will require a colormap matching the visual. Since the window we are interested in uses OpenGL's RGBA color model, we want a colormap configured for using RGB. The ICCCM establishes a means for sharing RGB colormaps between clients. XmuLookupStandardColormap is used to set up a colormap for the specified visual. The routine reads the ICCCM RGB_DEFAULT_MAP property on the X server's root window. If the property does not exist or does not have an entry for the specified visual, a new RGB colormap is created for the visual and the property is updated (creating it if necessary). Once the colormap has been created, XGetRGBColormaps finds the newly created colormap. The work for finding a colormap is done by the getColormap routine.

If a standard colormap cannot be allocated, glxdino will create an unshared colormap. For some servers, it is possible (though unlikely) a DirectColor visual might be returned (though the GLX specification requires a TrueColor visual be returned in precedence to a DirectColor visual if possible). To shorten the example code by only handling the most likely case, the code bails if a DirectColor visual is encountered. A more portable (and longer) program would be capable of initializing an RGB DirectColor colormap.



Next: 2.1.2 Creating a Rendering Up: 2.1 Initialization Previous: 2.1 Initialization


mjk@asd.sgi.com
Wed Oct 19 18:11:46 PDT 1994