`
liujiawinds
  • 浏览: 134602 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

wglMakeCurrent

API 
阅读更多
wglMakeCurrent 函数设定OpenGL当前线程的渲染环境。以后这个线程所有的OpenGL调用都是在这个hdc标识的设备上绘制。你也可以使用wglMakeCurrent 函数来改变调用线程的当前渲染环境,使之不再是当前的渲染环境。



BOOL wglMakeCurrent(
  HDC  hdc,      // device context of device that OpenGL calls are
                 // to be drawn on
  HGLRC  hglrc   // OpenGL rendering context to be made the calling
                 // thread's current rendering context
);



参数:

hdc

设备环境的句柄。调用这个函数的线程接下来的所有OpenGL调用都将在这个hdc所标识的设备上绘制。

hglrc

函数设定的OpenGL渲染环境的句柄,作为当前线程的渲染环境。

如果hglrc为NULL,函数将使调用线程的当前渲染环境不再作为当前的渲染环境,并释放这个渲染环境所使用的设备环境。这种情况下hdc参数将被忽略。



返回值:

当wglMakeCurrent 函数调用成功,将返回TRUE,否则返回FALSE,要想得到更多的信息,请调用

GetLastError。



注意:

hdc参数的绘制表面必须是支持OpenGL的。它不需是wglCreateContext 创建hglrc时所传进来的hdc,但它必须是相同的设备并具有相同的像素格式。GDI转换的hdc将不被渲染环境所支持。当前的渲染环境将一直使用hdc设备环境直到它不再是当前渲染环境。


在切换到新的渲染环境之前,OpenGL将冲刷掉当前调用线程之前的所有渲染环境。



一个线程可以有一个渲染环境。所以一个多线程进程可以有多个渲染环境。一个线程在调用任何OpenGL函数之前必须设置一个当前渲染环境。否则所有OpenGL调用都将忽略。



在某一时刻渲染环境只能属于一个线程,你不能使一个渲染环境同时属于多个线程。



一个应用程序可以通过不同线程中的不同的当前渲染环境产生多个绘图,它支持各个线程都拥有自己的渲染环境的设备环境。



如果有错误发生,wglMakeCurrent 函数在返回之前将使渲染环境不作为线程当前的渲染环境。



MSDN原文:

wglMakeCurrent
The wglMakeCurrent function makes a specified OpenGL rendering context the calling thread's current rendering context. All subsequent OpenGL calls made by the thread are drawn on the device identified by hdc. You can also use wglMakeCurrent to change the calling thread's current rendering context so it's no longer current.

BOOL wglMakeCurrent(
  HDC  hdc,      // device context of device that OpenGL calls are
                 // to be drawn on
  HGLRC  hglrc   // OpenGL rendering context to be made the calling
                 // thread's current rendering context
);
Parameters
hdc
Handle to a device context. Subsequent OpenGL calls made by the calling thread are drawn on the device identified by hdc.
hglrc
Handle to an OpenGL rendering context that the function sets as the calling thread's rendering context.
If hglrc is NULL, the function makes the calling thread's current rendering context no longer current, and releases the device context that is used by the rendering context. In this case, hdc is ignored.

Return Values
When the wglMakeCurrent function succeeds, the return value is TRUE; otherwise the return value is FALSE. To get extended error information, call GetLastError.

Remarks
The hdc parameter must refer to a drawing surface supported by OpenGL. It need not be the same hdc that was passed to wglCreateContext when hglrc was created, but it must be on the same device and have the same pixel format. GDI transformation and clipping in hdc are not supported by the rendering context. The current rendering context uses the hdc device context until the rendering context is no longer current.

Before switching to the new rendering context, OpenGL flushes any previous rendering context that was current to the calling thread.

A thread can have one current rendering context. A process can have multiple rendering contexts by means of multithreading. A thread must set a current rendering context before calling any OpenGL functions. Otherwise, all OpenGL calls are ignored.

A rendering context can be current to only one thread at a time. You cannot make a rendering context current to multiple threads.

An application can perform multithread drawing by making different rendering contexts current to different threads, supplying each thread with its own rendering context and device context.

If an error occurs, the wglMakeCurrent function makes the thread's current rendering context not current before returning.
分享到:
评论

相关推荐

    opengl画图程序附带源代码

    wglMakeCurrent(NULL,NULL)) // Are We Able To Release The DC And RC Contexts? { MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); } if (!wglDeleteContext...

    gertt点阵图读取器(opengl)

    wglMakeCurrent(NULL,NULL)) // Are We Able To Release The DC And RC Contexts? { MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); } if (!...

    在MFC中打印OpenGL

    - 使用 `wglMakeCurrent` 设置新的上下文,使其成为当前线程的OpenGL上下文,从而可以在打印机上进行渲染。 **3. 打印过程中的OpenGL渲染** - **代码片段**: ```cpp glViewport(l, b, w, h); OnDraw(pDC); ``...

    OpenGL.zip_mfc opengl_opengl 对话框_visual c_对话框

    这通常通过调用AfxGetMainWnd()->GetDC()获取设备上下文(Device Context, DC),然后创建一个支持OpenGL的扩展设备上下文(Extended Device Context, HDC),并使用wglMakeCurrent()激活该上下文。 2. **设置...

    在Windows环境中设置基于VC_的OpenGL图形接口

    - 使用 `wglCreateContext()` 创建 RC 并通过 `wglMakeCurrent()` 将其设置为当前 RC。 - 执行 OpenGL 绘图操作。 - 完成绘图后,通过 `wglMakeCurrent()` 断开 RC 与 DC 的联系,并删除 RC。 #### 实例演示 ...

    在对话框的控件中实现OpenGl三维绘图

    wglMakeCurrent(hdc, hglrc); // 初始化OpenGL状态,加载着色器等 InitializeOpenGL(); } ``` `InitializeOpenGL()`函数可以用来设置视口、投影、模型视图矩阵,加载顶点着色器和片段着色器,以及其他必要的...

    【demo】MFC下使用opengl

    6. **释放资源**:记得在不再使用OpenGL时,通过`wglMakeCurrent(NULL, NULL)`解除当前上下文,然后使用`wglDeleteContext()`删除渲染上下文,最后通过`ReleaseDC()`释放HDC。 这个【demo】将展示这些步骤的实现,...

    openGL应用程序

    首先,通过 `wglGetCurrentContext` 获取当前活动的OpenGL上下文(HGLRC),然后使用 `wglMakeCurrent(NULL, NULL)` 释放当前上下文。如果上下文存在,就使用 `wglDeleteContext` 删除它。最后,删除设备上下文对象...

    opengl绘制MFC绘制3D图形

    设置窗口类风格为WS_CLIPCHILDREN | WS_CLIPSIBLINGS,并调用wglMakeCurrent和glutInit来初始化OpenGL上下文和加载GLUT库。 2. **创建OpenGL上下文**:使用AfxGetInstanceHandle获取当前应用程序实例的句柄,然后...

    《虚拟现实与系统仿真》实验指导书22.docx

    wglMakeCurrent(dc.m_hDC, m_hRC); glMatrixMode(GL_PROJECTION); glLoadIdentity(); double d = 10; double n = 100; glOrtho(-cx / n, cx / n, -cy / n, cy / n, -d, d); glMatrixMode(GL_MODELVIEW); ...

    Setting Up OpenGL in an MFC Control

    这个过程涉及调用`wglMakeCurrent`、`wglCreateContext`和`wglGetProcAddress`等函数,以便能够执行OpenGL命令并在窗口上渲染。 代码示例: ```cpp if (!(hDC = GetDC())) return -1; hRC = wglCreateContext(hDC)...

    MFC.rar_SetupPixelFormat_mfc opengl

    wglMakeCurrent(m_hDC, m_hglRC)) return -1; return 0; } ``` **初始化OpenGL** 在成功创建GLRC后,我们可以在OnDraw()函数中初始化OpenGL。这包括加载GL库、设定视口和投影矩阵、以及进行其他必要的配置。 `...

    在MDI程序中使用opengl,在vc2005\vc6下均可以使用

    这通常在`OnDestroy`函数中完成,通过调用`wglMakeCurrent(NULL, NULL)`解除上下文与DC的关联,然后使用`wglDeleteContext`删除OpenGL上下文。 在提供的压缩包`glenabledview_demo`中,可能包含了一个示例程序,...

    基于MFC和OpenGL三维图形的开发

    - **创建OpenGL显示上下文**:使用`wglCreateContext`创建RC,并通过`wglMakeCurrent`将RC与DC关联,使OpenGL上下文生效。 - **绘制**:在WM_PAINT消息处理中,清除画布,执行OpenGL绘制命令,然后交换帧缓冲以...

    OpenGL.rar_openGL鼠标旋转_opengl_opengl 鼠标_visual c

    最后,确保在适当的地方释放资源并关闭OpenGL上下文,例如在`WM_DESTROY`消息处理中调用`wglMakeCurrent(NULL, NULL)`和`DeleteDC(hdc)`。 这个压缩包中的"旋转托动"可能是指同时支持物体的旋转和平移操作,也就是...

    在MFC中编写OPENGL对话框

    确保在每次绘制前调用`wglMakeCurrent()`来激活OpenGL上下文。 ```cpp afx_msg void OnPaint() { CPaintDC dc(this); // device context for painting wglMakeCurrent(dc.m_hDC, m_hGLRC); // 激活OpenGL上...

    本代码演示了如何在VC中使用OpenGL进行三维绘图.zip

    5. **清理资源**:在程序退出前,需要释放OpenGL资源,如删除纹理、卸载着色器等,最后通过`wglMakeCurrent(NULL, NULL)`和`wglDeleteContext(hdc)`释放OpenGL上下文。 在VC中,你可以使用Glew库来管理OpenGL版本和...

    mfc单文档下opengl渲染框架

    在其中,你可以调用`AfxGetMainWnd()->GetDC()`获取设备上下文(Device Context, DC),然后使用`wglCreateContext()`创建OpenGL上下文,最后通过`wglMakeCurrent()`将此上下文设为当前活动上下文。示例代码如下: ...

    第四节:Windows下的OpenGL_OpenGL_Win32__Wiggle.doc

    在Windows中,OpenGL通过Win32 API进行集成,引入了以`wgl`开头的特定函数,比如`wglCreateContext`、`wglDeleteContext`和`wglMakeCurrent`等,这些被称为“wiggle”函数。 首先,`wglCreateContext`用于创建...

    OPEN GL绘图—球

    这通常在窗口的WM_CREATE消息处理函数中完成,通过调用wglMakeCurrent、LoadLibrary、GetProcAddress等函数来设置OpenGL渲染上下文并加载OpenGL函数指针。 然后,我们将在窗口的WM_PAINT消息处理函数中实现绘制球体...

Global site tag (gtag.js) - Google Analytics