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.

Community
  • 1
  • 1
NmdMystery
  • 2,778
  • 3
  • 32
  • 60
  • 1
    Looks like your main problem was solved, so I won't post this as an answer. But your values in the pfd might also constrain finding a good pixel format. Most GPUs don't support 32-bit depth buffers, so 24 is normally a better value for `cDepthBits`. And `cColorBits` is the total number of bits for R, G, and B. So you're requesting a pixel format with more than 8 bits per component. – Reto Koradi Jul 15 '14 at 03:51

1 Answers1

3

Check the vendor string of your basic context. Also check whether other OpenGL programs are running correctly.

There are a few things that can completely disable use of graphics acceleration, mostly related to mirror drivers (remote desktop, screen recording, etc).

Also, some laptops have both integrated Intel1 graphics (iGPU) and discrete nVidia or AMD graphics (dGPU). Until the driver detects a game or benchmark running, the dGPU will be powered down to extend battery life.

In C or C++, for nVidia, there's a relatively simple way to request the dGPU for your application:

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

Unfortunately people are still searching for ways to do this for other hybrids, like AMD.


1 AMD makes processors with iGPUs also, but their capabilities are more complete (if slow), and if there's also a dGPU present, they work together in a form of unbalanced CrossFire. I therefore assume that explicitly enabling the dGPU isn't necessary in such cases. If you have an AMD APU (combo CPU+iGPU) and nVidia dGPU, I have no idea what happens.

Community
  • 1
  • 1
Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
  • The vendor string is "Intel" on his computer. I'm guessing something fishy is happening? – NmdMystery Jul 14 '14 at 21:19
  • @NmdMystery: You have hybrid graphics, aka Optimus? Your application isn't on the whitelist that causes the discrete GPU to be powered up, so you see the features of the Intel iGPU instead. There's supposed to be an Optimus library that provides a function you can call before OpenGL initialization, to power the nVidia GPU. Meanwhile, try running your application while the OpenGL caps program is forcing the dGPU on... – Ben Voigt Jul 14 '14 at 21:24
  • Well, that appears to be it. He's got an HD 4000 as well. – NmdMystery Jul 14 '14 at 21:36
  • @NmdMystery: So did you get in running in nVidia mode now, or do you need more help? – Ben Voigt Jul 14 '14 at 21:37
  • I basically have to use CUDA to wake it up, right? Otherwise I have no idea how to do that since I don't have an Nvidia card myself. – NmdMystery Jul 14 '14 at 21:39
  • @NmdMystery: Does this question help? http://stackoverflow.com/q/15372931/103167 and http://gamedev.stackexchange.com/a/58549 – Ben Voigt Jul 14 '14 at 21:43
  • Ah, I got it now. Thanks for the help! – NmdMystery Jul 14 '14 at 21:45