Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
MSDN Library

wglCreateContext

The wglCreateContext function creates a new OpenGL rendering context, which is suitable for drawing on the device referenced by hdc. The rendering context has the same pixel format as the device context.

HGLRC wglCreateContext(
  HDC  hdc   // device context of device that the rendering context 
             // will be suitable for
);

Parameters

hdc
Handle to a device context for which the function creates a suitable OpenGL rendering context.

Return Values

If the function succeeds, the return value is a valid 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 not the same as a device context. Set the pixel format of the device context before creating a rendering context. For more information on setting the device context's pixel format, see the SetPixelFormat function.

To use OpenGL, you create a rendering context, select it as a thread's current rendering context, and then call OpenGL functions. When you are finished with the rendering context, you dispose of it by calling the wglDeleteContext function.

The following code example shows wglCreateContext usage:

HDC    hdc; 
HGLRC  hglrc; 
 
// create a rendering context 
hglrc = wglCreateContext (hdc); 
 
// make it the calling thread's current rendering context
wglMakeCurrent (hdc, hglrc);
 
// call OpenGL APIs as desired ...
 
// 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, SetPixelFormat, wglDeleteContext, wglGetCurrentContext, wglGetCurrentDC, wglMakeCurrent


  

Community Additions

Show:
© 2015 Microsoft