wglCreateLayerContext

The wglCreateLayerContext function creates a new OpenGL rendering context for drawing to a specified layer plane on a device context.

HGLRC wglCreateLayerContext(
  HDC  hdc,          // device context used for a rendering context
  int  iLayerPlane   // specifies the layer plane that a rendering 
                     // context is bound to
);

Parameters

hdc
Specifies the device context for a new rendering context.
iLayerPlane
Specifies the layer plane to which you want to bind a rendering context. The value 0 identifies the main plane. Positive values of iLayerPlane identify overlay planes, where 1 is the first overlay plane over the main plane, 2 is the second overlay plane over the first overlay plane, and so on. Negative values identify underlay planes, where 1 is the first underlay plane under the main plane, 2 is the second underlay plane under the first underlay plane, and so on. The number of overlay and underlay planes is given in the bReserved member of the PIXELFORMATDESCRIPTOR structure.

Return Values

If the function succeeds, the return value is a handle to an OpenGL rendering context.

If the function fails, the return value is NULL. To get extended error information, call GetLastError.

Remarks

A rendering context is a port through which all OpenGL commands pass. Every thread that makes OpenGL calls must have one current, active rendering context. A rendering context is not the same as a device context; a rendering context contains information specific to OpenGL, while a device context contains information specific to GDI.

Before you create a rendering context, set the pixel format of the device context with the SetPixelFormat function. You can use a rendering context in a specified layer plane of a window with identical pixel formats only.

With OpenGL applications that use multiple threads, you create a rendering context, select it as the current rendering context of a thread, and make OpenGL calls for the specified thread. When you are finished with the rendering context of the thread, call the wglDeleteContext function. The following code example shows how to use wglCreateLayerContext.

// The following code fragment shows how to render to overlay 1 
// This example assumes that the pixel format of hdc includes  
// overlay plane 1 
 
HDC hdc; 
HGLRC; 
 
// create a rendering context for overlay plane 1 
hglrc = wglCreateLayerContext(hdc, 1); 
 
// make it the calling thread's current rendering context 
wglMakeCurrent(hdc, hglrc); 
 
// call OpenGL functions here. . . 
 
// when the rendering context is no longer needed. . . 
 
// make the rendering context not current 
wglMakeCurrent(NULL, NULL); 
 
// delete the rendering context 
wglDeleteContext(hglrc); 

Requirements

  Windows NT/2000: Requires Windows NT 3.5 or later.
  Windows 95/98: Requires Windows 95 or later. Available as a redistributable for Windows 95.
  Header: Declared in wingdi.h.
  Import Library: Use opengl32.lib.

See Also

OpenGL on Windows NT, Windows 2000, and Windows 95/98, WGL Functions, PIXELFORMATDESCRIPTOR, SetPixelFormat, wglCreateContext, wglDeleteContext, wglGetCurrentContext, wglGetCurrentDC, wglMakeCurrent


  

Community Additions

Show: