WglCreateContext函數作用

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章