wglMakeCurrent失败,返回1282
wglMakeCurrent fails with 1282
我正在使用OpenGL创建一个visual studio Win32应用程序。然而,当我调用glewInit,然后调用GetLastError()时,我得到错误127("找不到指定的过程。")我静态链接到opengl,如下所示:
#define GLEW_STATIC
#include <glew.h>
#include <wglew.h>
#include <gl/gl.h>
#include <gl/glu.h>
// link with libraries
#pragma comment(lib, "openGL32.lib")
#pragma comment(lib, "glu32.lib")
#pragma comment(lib, "glew32s.lib")
我的猜测是,由于某种原因,我的应用程序在运行时找不到函数,但我不确定为什么,这让我抓狂。我尝试过将库直接放在可执行目录中,但没有成功。以下是违规代码:
// create a device context
m_deviceContext = GetDC(m_windowHandle);
// choose a pixel format
PIXELFORMATDESCRIPTOR pfd;
memset(&pfd, 0, sizeof(pfd));
pfd.nSize = sizeof(pfd);
pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW; // double-buffering, opengl, and render to window
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32; // 32 bits of color information (the higher, the more colors)
pfd.cDepthBits = 32; // 32 bits of color information (the higher, the more depth levels)
pfd.iLayerType = PFD_MAIN_PLANE;
int pixelFormat = ChoosePixelFormat(m_deviceContext, &pfd);
assert(pixelFormat);
// set the pixel format
BOOL res = SetPixelFormat(m_deviceContext, pixelFormat, &pfd);
assert(res);
// this creates an openGL 2.1 context for the device context
HGLRC tempContext = wglCreateContext(m_deviceContext);
wglMakeCurrent(m_deviceContext, tempContext);
// enable GLEW so we can try to create a 3.2 context instead
DWORD error = GetLastError();
GLenum err = glewInit();
error = GetLastError();
assert(err == GLEW_OK);
关于我的设置的一些细节。我将工作目录更改为可执行文件的生成位置(($ProjectDir)\Binaries\Win32)在此之前,一切都很顺利。我尝试添加额外的依赖项并更改额外的库目录,但没有成功。
我的程序缺少什么来查找glewInit过程?我感谢任何帮助或建议。
EDIT:glGetError()在对wglMakeCurrent():进行此调用后返回1282(INVALID_OPERATION)
// attempt to create the opengl 3.2 context
int attr[] = {
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
WGL_CONTEXT_MINOR_VERSION_ARB, 2,
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
0
};
if(wglewIsSupported("WGL_ARB_create_context") == 1)
{
CheckOpenGLError();
m_renderContext = wglCreateContextAttribsARB(m_deviceContext, NULL, attr);
CheckOpenGLError();
wglMakeCurrent(NULL, NULL);
CheckOpenGLError(); // <-- This guy calls glGetError() and returns 1282
wglDeleteContext(tempContext);
CheckOpenGLError();
wglMakeCurrent(m_deviceContext, m_renderContext);
}
我认为问题不是。相反,我的问题似乎是对wglMakeCurrent的调用失败了,我无法渲染到我的窗口。经过一些研究,这里的文档表明,使用NULL作为HDC调用是完全有效的,因为它被忽略了,并且渲染上下文应该不是最新的。
新问题:wglMakeCurrent(NULL,NULL)失败的原因是什么?为了以防万一,我也尝试过wglMakeCurrent(m_deviceContext,NULL),但也失败了。
我正在使用OpenGL创建一个visual studio Win32应用程序。然而,当我调用glewInit然后调用GetLastError()时,我得到错误127("找不到指定的过程")
GLEW可能在初始化后使OpenGL处于错误状态,这是一个众所周知的问题。忽略它。初始化GLEW的惯用方法是
if( GLEW_OK != glewInit() ) {
handle_glew_init_error_condition();
}
else {
/* flush the OpenGL error state, ignoring all errors */
while( GL_NO_ERROR != glGetError() );
}
请注意,您必须在循环中调用glGetError,因为允许设置多个错误条件,并且glGetError只报告并逐个清除它们。
我静态链接到opengl如下:
当然不是。CCD_ 1文件也可以用于动态链接;在这种情况下,它们包含DLL的名称和入口点表。
关于wglMakeCurrent(NULL,NULL)的更新
一旦您解除了OpenGL上下文的绑定,glGetError应该从什么错误状态报告?没有OpenGL上下文可以使用,所以它会向您报告。glGetError本身正在执行一个无效的操作,因为您调用它时没有激活OpenGL上下文。
- 来自 std::list 的迭代器 .end() 按预期返回"0xcdcdcdcdcdcdcdcd"但 .begin()
- 什么时候在C++中返回常量引用是个好主意
- 你能重载对象变量名本身返回的内容吗
- 为什么 Serial.println(<char[]>);返回随机字符?
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- 如何获取std::result_of函数的返回类型
- QueryWorkingSet总是返回false
- (C++)分析树以计算返回错误值的简单算术表达式
- 访问者访问变体并返回不同类型时出错
- 如何返回一个类的两个对象相加的结果
- OpenInventor从9.8升级到10.4.2后,GLSL纹理返回零
- lower_bound()返回最后一个元素
- "throw expression code" 1e7 >返回 d 是什么?投掷标准::overflow_error( "too big" ) : d;意味 着?
- 奇怪的(对我来说)返回声明 - 在谷歌上找不到任何关于它的信息
- 如何取消对nullptr的屏蔽,返回正确的对象
- 奇怪的结构&GCC&clang(void*返回类型)
- 架构决策:返回std::future还是提供回调
- glReadPixels函数返回错误1282(GL_INVALID_OPERATION)
- wglMakeCurrent失败,返回1282
- glGetError无限返回1282