Porting Device Contexts and Pixel Formats

Each window in the Microsoft implementation of OpenGL for Windows NT and Windows 95 has its own current pixel format. A pixel format is defined by a PIXELFORMATDESCRIPTOR data structure. Because each window has its own pixel format, you obtain a device context, set the pixel format of the device context, and then create an OpenGL rendering context for the device context. The rendering context automatically uses the pixel format of its device context.

The X Window System also uses a data structure, XVisualInfo, to specify the properties of pixels in a window. XVisualInfo structures contain a Visual data structure that describes how color resources are used in a specific screen.

In the X Window System, XVisualInfo is used to create a window by setting the window to the pixel format you want. The returned structure is used to create the window and a rendering context. In Windows NT and Windows 95, you first create a window and get a handle to a device context (HDC) of the window. The HDC is then used to set the pixel format for the window. The rendering context uses the pixel format of the window.

The following table compares the X Window System and GLX visual functions with their equivalent Win32 pixel format functions.

X Window/GLX Visual Function Win32 Pixel Format Function
XVisualInfo*
glXChooseVisual(Display *dpy,
int screen,
int *attribList)
int ChoosePixelFormat(HDC hdc,
PIXELFORMATDESCRIPTOR *ppfd)
int glXGetConfig(Display *dpy,
XVisualInfo *vis,
int *attribList,
int *value)
int DescribePixelFormat(HDC hdc,
int iPixelFormat,
UINT nBytes,
LPPIXELFORMATDESCRIPTOR ppfd)
XVisualInfo*
XGetVisualInfo(Display *dpy,
long vinfo_mask,
XVisualInfo *vinfo_templ,
int *nitems)
int GetPixelFormat(HDC hdc)
The visual returned by glxChooseVisual is used when a window is created. BOOL SetPixelFormat(HDC hdc,
int iPixelFormat,
PIXELFORMATDESCRIPTOR *ppfd)

The following sections give examples of pixel format code fragments for an X Window System program, and the same code after it has been ported to Windows NT and Windows 95.

For more information on pixel formats, see Pixel Formats.