Though each OpenGL window system interface is different they are all similar in functionality. This document compares the functionality of several interfaces. Programmers writing applications for more than one window systems should find this information especially relevant.
The following interfaces are compared:
Datatypes
Datatypes
Datatypes
An OpenGL rendering context is activated by binding a context to
a window or drawable.
Datatypes
The application programmer should know what frame buffer attributes are
needed and select a visual or pixel format accordingly.
These functions return a visual or pixel format based
on a attribute list provided by the programmer.
Direct contexts provide a means of utilizing local
graphics hardware in the most efficient means possible. Indirect contexts
are used in other situations such as when rendering remotely.
In the case of GLX, a direct context may be used when using local graphics
hardware; the GLX protocol encoding/decoding is bypassed.
An indirect context allows remote display to X servers which
support the GLX extension.
Some OpenGL interfaces make no distinction between direct and indirect
rendering.
BOOL wglShareLists( HGLRC hglrc1, HGLRC hglrc2 )
GLboolean aglDestroyAGLPixmap( AGLPixmap pix )
void glXDestroyGLXPixmap( Display *dpy, GLXPixmap pix );
BOOL wglUseFontOutlines( HDC hdc, DWORD first, DWORD count, DWORD listBase,
FLOAT deviation, FLOAT extrusion, int format,
LPGLYPHMETRICSFLOAT lpgmf )
AGLDrawable aglGetCurrentDrawable( void )
GLXDrawable glXGetCurrentDrawable( void )
HWND pglGetCurrentWindow( HAB hab )
HDC wglGetCurrentDC( void )
int GetPixelFormat( HDC hdc )
void glXWaitX( void )
void pglWaitPM( HAB hab )
Returns the current error setting or GL_OK if none.
Returns a list of all pixel formats offered for the given device.
Sets AGL-specific options.
Causes the current context's state to be updated from the window system.
This should be called whenever the window is moved, resized, or the screen
resolution or depth is changed.
Returns a list of space separated GLX extensions on the specified display.
Returns a string describing an attribute of the OpenGL client library.
Returns a string describing an attribute of the OpenGL display server.
This function specifies the color index palette for OpenGL to use when drawing
in RGB mode.
BOOL pglReleaseFrontBitmap( HAB hab )
These functions are used to gain exclusive access to a window.
Provide support for overlay and underlay color buffers.
3. Data types and objects
There are several data types or handles which are used for similar
purposes in all the OpenGL interfaces.
Display
HAB
HDC
AGLPixelFmtID
XVisualInfo
PVISUALCONFIG
an integer pixel format number
or a PIXELFORMATDESCRIPTOR structure
AGLContext
GLXContext
HGC
HGLRC
AGLDrawable
GLXDrawable (a Window or GLXPixmap)
HWND
HDC
4. Interface Functions
This section presents the major function of the interfaces catagorized
according to their purpose.
4.1 Testing for OpenGL availability
At runtime it may be necessary to determine if a display or terminal is
capable of OpenGL rendering.
Bool glXQueryExtension( Display *dpy, int *errorBase, int *eventBase )
LONG pglQueryCapability( HAB hab )
4.2 Getting OpenGL version information
Since OpenGL is an evolving standard it's sometimes useful to be able to
determine which version of OpenGL render is being used.
GLboolean aglQueryVersion( int *major, int *minor )
Bool glXQueryVersion( Display *dpy, int *major, int *minor )
void pglQueryVersion( HAB hab, int *major, int *minor )
4.3 Selection of a visual or pixel format
A visual or pixel format describes the frame buffer and ancillary buffers.
Attributes include RGB vs color index, bits per color component, single vs
double buffered, size of depth buffer, size of stencil buffer, etc.
AGLPixelFmtID aglChoosePixelFmt( GDHandle *dev, int ndev, int *attribs )
XVisualInfo* glXChooseVisual( Display *dpy, int screen, int *attribList )
PVISUALCONFIG pglChooseConfig( HAB hab, int *attriblist )
int ChoosePixelFormat( HDC hdc, PIXELFORMATDESCRIPTOR *pfd )
4.4 Query visual/pixel format attributes
As an alternative to asking the window system for a visual/pixel format
which matches an attribute list, one may query the attributes of a particular
visual or pixel format.
This allows the programmer complete control over visual/pixel format selection.
These functions return the value of an attribute for a given visual/pixel
format.
GLboolean aglGetConfig( AGLPixelFmtID pix, int attrib, int *value )
int glXGetConfig( Display *dpy,
XVisualInfo *vis,
int attrib,
int *value )
PVISUALCONFIG *pglQueryConfigs( HAB hab )
int DescribePixelFormat( HDC hdc, int pixelformat, UINT bytes,
LPPIXELFORMATDESCRIPTOR pfd )
4.5 Creating a rendering context
After a visual/pixel format has been selected an OpenGL rendering context
may be allocated. Rendering contexts may share display lists and texture
maps if the contexts are compatible. Contexts are considered to be
compatible if they share the same address space and pixel format and are
both direct or indirect.
AGLContext aglCreateContext( AGLPixelFmtID pix,
AGLContext shareList )
GLXContext glXCreateContext( Display *dpy,
XVisualInfo *vis,
GLXContext shareList,
Bool direct )
HGC pglCreateContext( HAB hab,
PVISUALCONFIG pVisualConfig,
HGC ShareList,
BOOL IsDirect )
HGLRC wglCreateContext( HDC hdc )
4.6 Destroying a rendering context
When finished with a context it may be destroyed.
GLboolean aglDestroyContext( AGLContext ctx )
void glXDestroyContext( Display *dpy, GLXContext ctx )
BOOL pglDestroyContext( HAB hab, HGC hgc )
wglDeleteContext( HRC hrc )
4.7 Context binding
When a rendering context is bound to a window it becomes the current
context. OpenGL rendering may then begin. Note that it is
not until this point that one may test for OpenGL extensions.
GLboolean aglMakeCurrent( AGLDrawable drawable, AGLContext ctx )
Bool glXMakeCurrent( Display *dpy, GLXDrawable drawable, GLXContext ctx )
BOOL pglMakeCurrent( HAB hab, HGC hgc, HWND hwnd )
wglMakeCurrent( HDC hdc, HGLRC hrc )
4.8 Copying context state
These functions copy a subset of a context state from one context to another.
The mask parameter takes the same values as glPushAttrib().
GLboolean aglCopyContext( AGLContext src, AGLContext dst, GLuint mask )
void glXCopyContext( Display *dpy,
GLXContext src,
GLXContext dst,
GLuint mask )
BOOL pglCopyContext( HAB hab, HGC hgc_src, HGC hgc_dst,
GLuint attrib_mask )
BOOL wglCopyContext( HGLRC hglrcSrc, hglrcDst, UINT mask )
4.9 Testing for direct rendering
These functions test if a rendering context is direct.
Bool glXIsDirect( Display *dpy, GLXContext ctx )
LONG pglIsIndirect( HAB hab, HGC hgc )
4.10 Swapping color buffers
The swap buffers operation exchanges the front and back color
buffers when double buffering is enabled. The contents of the back buffer
become undefined after the swap operation.
GLboolean aglSwapBuffers( AGLDrawable drawable )
void glXSwapBuffers( Display *dpy, GLXDrawable drawable )
void pglSwapBuffers( HAB hab, HWND hwnd )
BOOL SwapBuffers( HDC hdc )
4.11 Off-screen rendering
These functions create an off-screen color buffer or pixmap. Be aware that
rendering to an off-screen color buffer may not be
accelerated by your graphics hardware.
AGLPixmap aglCreateAGLPixmap( AGLPixelFmtID pix, GWorldPtr pixmap )
GLXPixmap glXCreateGLXPixmap( Display *dpy, XVisualInfo *vis, Pixmap pixmap )
4.12 Bitmap fonts
Fonts provided by the window system may be converted to glBitmap()
format and stored in display lists. Character strings may then be
rendered with glCallLists(). These functions convert font
glyphys from the window system to a sequence of display lists.
GLboolean aglUseFont( int familyID, int size, int first,
int count, int listBase )
void glXUseXFont( Font font, int first, int count, int listBase )
BOOL pglUseFont( HAB hab, HPS hps, FATTRS fatAttrs, LONG llcid,
int first, int count, int listbase )
BOOL wglUseFontBitmaps( HDC hdc, DWORD first, DWORD count, DWORD listBase )
4.13 Querying the current context and drawable
The ID of the current rendering context and current window/drawable may
be queried with these functions.
AGLContext aglGetCurrentContext( void )
GLXContext glXGetCurrentContext( void )
HGC pglGetCurrentContext( HAB hab )
HGLRC wglGetCurrentContext( void )
4.14 Synchronization
Since both OpenGL and the native window system renderer may both draw into
the same window synchronization is needed to be sure operations are performed
in the correct order.
void glXWaitGL( void )
HPS pglWaitGL( HAB hab )
4.15 Miscellaneous
Each OpenGL window system interface has some unique functions. Some of
them are described here.
GLenum aglGetError( void )
int aglListPixelFmts( GDHandle dev, AGLPixelFmtID **fmts )
GLboolean aglSetOptions( int options )
GLboolean aglUpdateCurrent( void )
const char *glXGetClientString( Display *dpy, int name )
const char *glXQueryServerString( Display *dpy, int screen, int name )
INT pglSelectColorIndexPalette( HAB hab, HPAL hpal, HGC hgc )
BOOL pglGrabFrontBitmap( HAB hab, HPS phps, HBITMAP phbitmap )
wglCreateLayerContext, wglDescribeLayerPlane, wglGetLayerPaletteEntries,
wglSetLayerPaletteEntries, and wglSwapLayerBuffers
5. To learn more
Introduction to OpenGL and X, Part 1: An Introduction
(http://www.sgi.com/Technology/openGL/mjk.intro/intro.html)
by Mark Kilgard of SGI
describes how to get started with OpenGL and the X Window System.
The Unix man pages for GLX and the GLX specification documents describe the GLX functions in detail.
agl.txt describes the AGL interface. This information provided courtesy of Template Graphics Software.
OpenGL for OS/2 including documentation can be obtained from ftp://ftp.austin.ibm.com/pub/developer/os2/OpenGL/.
Using OpenGL in Visual C++ Version 4.x (http://www.iftech.com/oltc/opengl/opengl0.stm) by N. Alan Oursland of Interface Technologies, Inc. describes how to get started using OpenGL with Microsoft's Visual C++.
OpenGL I: Quick Start (http://www.microsoft.com/msdn/library/technote/gl1.htm) by Dale Rogerson of Microsoft is the first in a series of articles explaining how to use OpenGL with Windows 95 and Windows Nt.
Microsoft's Developer Studio / Visual C++ product includes online documentation of the WGL interface.