我正在使用Win32创建一个可视化studio OpenGL应用程序。但是,当我调用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)\二进制\Win32 32)。在这之前一切顺利。我尝试添加额外的依赖项并更改附加的库目录,但没有成功。
为了我的程序找到glewInit过程,我遗漏了什么?我感谢任何帮助或建议。
编辑: 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),以防万一,但也失败了。
发布于 2015-02-23 09:16:12
我正在使用Win32创建一个可视化studio OpenGL应用程序。但是,当我调用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,如下所示:
哪儿有的事儿。当然不是。.lib文件也可用于动态链接;在这种情况下,它们包含DLL的名称和入口点表。
关于wglMakeCurrent的更新(NULL,NULL)
一旦您解除了OpenGL上下文的绑定,glGetError应该从什么错误状态报告?没有它可以使用的OpenGL上下文,所以它会向您报告。glGetError本身正在执行无效的操作,因为您调用它时没有激活OpenGL上下文。
https://stackoverflow.com/questions/28663167
复制相似问题