WglCreateContext 函数详解

来源:互联网 发布:禅城数据便民服务中心 编辑:程序博客网 时间:2024/05/16 17:07
WglCreateContext

WglCreateContext函数创建一个新的OpenGL渲染描述表,此描述表必须适用于绘制到由hdc返回的设备.这个渲染描述表将有和设备上下文(dc)一样的像素格式.
HGLRC wglCreateContext(

   HDC hdc    // device context of device that the rendering context

              // will be suitable for

);

Parameters

hdc
用于函数将要创建的适合的OpenGL渲染描述表的设备上下文(dc)句柄.

Return Values
如果函数调用成功,返回有效的OpenGL渲染描述表句柄.否则返回NULL.

Remarks
渲染描述表并不等于设备描述表,创建渲染描述表之前应该仙设置设备描述表的像素格式.获得更多的设置设备描述表的像素格式的信息可以查看函数SetPixelFormat.
使用OpenGL, 你创建一个渲染描述表,选则它作为一个线程的当前渲染描述表,然后再调用OpenGL函数.当你使用完渲染描述表以后,记得调用wglDeleteContext函数释放掉这个渲染描述表
wglCreateContext

The wglCreateContextfunction 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);