资源泄漏opengl/win32
Resource Leak opengl/win32
你好,我最近开始学习win32/opengl,我设法写了一个在窗口内显示多色立方体的函数。我的问题是有一个资源泄漏,但我被难住了,不知道我到底忘记删除什么。
我已经把它缩小到这个函数
void display()
{
g.hglrc = wglCreateContext(g.hdc);
wglMakeCurrent(g.hdc, g.hglrc);
// make the color a white hue
glClearColor(1.0F, 1.0F, 1.0F, 1.0F);
// Clear screen and Z-buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Reset transformations
glLoadIdentity();
// Rotate when user changes rotate_x and rotate_y
glRotatef(rotate_x, 1.0, 0.0, 0.0);
glRotatef(rotate_y, 0.0, 1.0, 0.0);
//Multi-colored side - FRONT
glBegin(GL_POLYGON);
glColor3f(1.0, 0.0, 0.0); glVertex3f(0.5, -0.5, -0.5); // P1 is red
glColor3f(0.0, 1.0, 0.0); glVertex3f(0.5, 0.5, -0.5); // P2 is green
glColor3f(0.0, 0.0, 1.0); glVertex3f(-0.5, 0.5, -0.5); // P3 is blue
glColor3f(1.0, 0.0, 1.0); glVertex3f(-0.5, -0.5, -0.5); // P4 is purple
glEnd();
// White side - BACK
glBegin(GL_POLYGON);
glColor3f(1.0, 1.0, 1.0);
glVertex3f(0.5, -0.5, 0.5);
glVertex3f(0.5, 0.5, 0.5);
glVertex3f(-0.5, 0.5, 0.5);
glVertex3f(-0.5, -0.5, 0.5);
glEnd();
// Purple side - RIGHT
glBegin(GL_POLYGON);
glColor3f(1.0, 0.0, 1.0);
glVertex3f(0.5, -0.5, -0.5);
glVertex3f(0.5, 0.5, -0.5);
glVertex3f(0.5, 0.5, 0.5);
glVertex3f(0.5, -0.5, 0.5);
glEnd();
// Green side - LEFT
glBegin(GL_POLYGON);
glColor3f(0.0, 1.0, 0.0);
glVertex3f(-0.5, -0.5, 0.5);
glVertex3f(-0.5, 0.5, 0.5);
glVertex3f(-0.5, 0.5, -0.5);
glVertex3f(-0.5, -0.5, -0.5);
glEnd();
// Blue side - TOP
glBegin(GL_POLYGON);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(0.5, 0.5, 0.5);
glVertex3f(0.5, 0.5, -0.5);
glVertex3f(-0.5, 0.5, -0.5);
glVertex3f(-0.5, 0.5, 0.5);
glEnd();
// Red side - BOTTOM
glBegin(GL_POLYGON);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(0.5, -0.5, -0.5);
glVertex3f(0.5, -0.5, 0.5);
glVertex3f(-0.5, -0.5, 0.5);
glVertex3f(-0.5, -0.5, -0.5);
glEnd();
wglMakeCurrent(NULL, NULL);
SwapBuffers(g.hdc);
ReleaseDC(g.hwnd, g.hdc);
wglDeleteContext(g.hglrc);
}
g.hglrc = wglCreateContext(g.hdc);
别那样做。
您不需要在每次需要重新绘制屏幕时创建渲染上下文。你创建它一次;只有当你的窗口消失时,它才会消失。
现在,这并不一定证明为什么创建和销毁渲染上下文会留下资源。但这无关紧要;你不应该因为性能而这样做。呈现上下文的创建和销毁不是一个快速的过程,也不打算如此。
相关文章:
- OpenGL - 在抛出"__gnu_cxx::recursive_init_error"实例后终止调用?
- Win32编译器选项和内存分配
- 了解 GLM- openGL 中的相机转换
- 如何在全屏模式下(在OpenGL中)使背景透明
- 为什么我不能使用 EGL 创建无头 OpenGl 上下文?
- OpenGL大的3D纹理(>2GB)非常慢
- OpenGl glm rotate
- C++atioglxx.pdb未加载错误glBufferData OpenGL
- 我如何将Win32窗口渲染到OpenGL纹理
- Win32 消息队列在使用 OpenGL 渲染时被淹没
- 如何在OpenGL或Win32中获取图形卡模型名称
- OpenGL 的 Win32 主消息循环
- Opengl:呈现到 Win32 API 上下文
- 如何在Win32(C++)静态控件中正确渲染OpenGL
- 在 OpenGL Win32 上激活多重采样
- 在窗口标题和消息框中显示错误的语言:win32应用程序,opengl
- 尝试将着色器与 Win32 OpenGL 一起使用,但顶点着色器不绘制任何内容
- 资源泄漏opengl/win32
- 使用Unity3D作为GUI的Win32 c++与OpenGL应用程序
- 如何使用Win32 API的开发模式扩展OpenGL全屏应用程序?