首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >wglMakeCurrent在1282中失败

wglMakeCurrent在1282中失败
EN

Stack Overflow用户
提问于 2015-02-22 20:59:17
回答 1查看 1.7K关注 0票数 0

我正在使用Win32创建一个可视化studio OpenGL应用程序。但是,当我调用glewInit,然后调用GetLastError()时,会得到错误127 (“找不到指定的过程”)。我静态地链接到opengl,如下所示:

代码语言:javascript
复制
#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")

我的猜测是,由于某种原因,在运行时,我的应用程序找不到这个函数,但我不知道为什么,它让我发疯了。我尝试将库直接放置在可执行目录中,但没有成功。以下是违规代码:

代码语言:javascript
复制
      // 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):

代码语言:javascript
复制
  // 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),以防万一,但也失败了。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-02-23 09:16:12

我正在使用Win32创建一个可视化studio OpenGL应用程序。但是,当我调用glewInit,然后调用GetLastError()时,会得到错误127 (“找不到指定的过程”)。

GLEW在初始化后可能会使OpenGL处于错误状态,这一直是众所周知的问题。忽略它。初始化GLEW的惯用方法是

代码语言:javascript
复制
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上下文。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28663167

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档