2

I have a program which creates an OpenGL 4.0 context on a Windows machine. On my own computer, this code works - however, on my friend's computer, it does not. wglCreateContextAttribsARB returns NULL, even though my friend's Nvidia card supports OpenGL 4.4 and should be able to return a backwards-compatible context. Every other call does as expected.

This is the context creation code:

dc = GetDC(window::get());

PIXELFORMATDESCRIPTOR pfd = { 0 };
pfd.nSize = sizeof(pfd);
pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cDepthBits = 32;

int nPixelFormat = ChoosePixelFormat(dc, &pfd);
SetPixelFormat(dc, nPixelFormat, &pfd);
HGLRC tempRC = wglCreateContext(dc);
wglMakeCurrent(dc, tempRC);
glewInit();

static const int attributes[] = {
    WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
    WGL_CONTEXT_MINOR_VERSION_ARB, 0,
    NULL
};

rc = wglCreateContextAttribsARB(dc, NULL, attributes);

if (rc == NULL) {
    abort();
}

wglMakeCurrent(NULL, NULL);
wglDeleteContext(tempRC);
wglMakeCurrent(dc, rc);

glClearColor(0.2, 0.4, 0.6, 1.0);
glEnable(GL_DEPTH_TEST);
wglSwapIntervalEXT(1);

Another person had a similar problem and posted this question here. However, the thing that fixed the problem for them is not fixing the problem for me. I'm completely stumped.

4

1 回答 1

3

检查您的基本上下文的供应商字符串。还要检查其他 OpenGL 程序是否正常运行。

有一些事情可以完全禁用图形加速,主要与镜像驱动程序(远程桌面、屏幕录制等)有关。

此外,一些笔记本电脑同时集成了 Intel 1显卡 (iGPU) 和独立的 nVidia 或 AMD 显卡 (dGPU)。在驱动程序检测到游戏或基准测试运行之前,dGPU 将关闭以延长电池寿命。

在 C 或 C++ 中,对于 nVidia,有一种相对简单的方法可以为您的应用程序请求 dGPU:

extern "C" { _declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001; }

不幸的是,人们仍在为其他混合动力车寻找方法,例如 AMD


1 AMD 也使用 iGPU 制造处理器,但它们的功能更完整(如果速度较慢),并且如果还存在 dGPU,它们会以不平衡 CrossFire 的形式协同工作。因此,我假设在这种情况下不需要显式启用 dGPU。如果你有 AMD APU(组合 CPU+iGPU)和 nVidia dGPU,我不知道会发生什么。

于 2014-07-14T21:16:56.037 回答