Next: 4 A Simple Example Up: OpenGL and X Previous: 2.6 The GLU Library

3 OpenGL's X Support

GLX is an official part of the OpenGL standard for supporting the X Window System. It provides additional routines (prefixed by glX) for interfacing OpenGL with X. It also defines a wire protocol for supporting OpenGL as an X server extension. The GLX wire protocol allows workstations from different vendors to interoperate using 3D graphics the same way the X protocol provides 2D graphics interoperability. Some of the issues about integrating X and OpenGL are discussed by Karlton [3].

GLX allows rendering into X windows and pixmaps. An X server can support different visuals to describe the different types of windows supported by the server. For the core X protocol, a visual specifies one (or more) depths for the frame buffer and how pixel values are mapped to colors on the screen. X treats a drawable as basically a 2D array of pixels, but OpenGL has a much more sophisticated view of a drawable's frame buffer capabilities. GLX overloads the core X notion of a visual by associating additional information about OpenGL's frame buffer capabilities. In addition to an image buffer, OpenGL supports various types of ancillary buffers. For example, a window might also have a stencil buffer and a depth buffer. Modes such as stereo and double buffering are also supported. Multiple different frame buffer configurations can be supported by a single X server by exporting multiple visuals.

All OpenGL implementations for the X Window System must support at least one RGBA visual and at least one color index visual. Both visuals must support a stencil buffer of at least 1 bit and a depth buffer of at least 12 bits The required RGBA visual must have an accumulation buffer. The alpha component of the image buffer is not required for the RGBA visual (but input alpha is still used in all rendering calculations). Many implementations will supply many more than two visuals.

The GLX API supplies two routines, glXGetConfig and glXChooseVisual, to help programmers select an appropriate visual. Once the appropriate visual is selected, call XCreateWindow with the selected visual to create the window.

GLX supports off-screen rendering to pixmaps. First create a standard X pixmap of the desired depth using XCreatePixmap. Then call glXCreateGLXPixmap with the desired OpenGL visual. A new drawable of type GLXPixmap is returned which can be used for drawing OpenGL into the pixmap.

To render using OpenGL, an OpenGL rendering context must be created. The glXCreateContext routine creates such a context. An option to glXCreateContext allows the programmer to specify that direct rendering to the hardware should be done if supported by the implementation.

Before rendering, a rendering context must be bound to the desired drawable using glXMakeCurrent. OpenGL rendering commands implicitly use the current bound rendering context and one drawable. Just as a program can create multiple windows, a program can create multiple OpenGL rendering contexts. But a thread can only be bound to one rendering context and drawable at a time. Once bound, OpenGL rendering can begin. glXMakeCurrent can be called again to bind to a different window and/or rendering context.

The GLX stream of commands is considered distinct from the stream of X requests. Sometimes you may want to mix OpenGL and X rendering into the same window. If so synchronization can be achieved using the glXWaitGL and glXWaitX routines.

To swap the buffers of a double buffered window, glXSwapBuffers can be called. X fonts can be converted into per-glyph OpenGL display lists using the glXUseXFont routine.



Next: 4 A Simple Example Up: OpenGL and X Previous: 2.6 The GLU Library


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