18

I know how to open a window with openGL (using Win32 or other toolkits). But when the system have 2 graphics cards. How do I select a graphic device to render? My programming language is C++ and I'm focusing on windows but any sample will be welcome.

Edit: Maybe Its a good idea to explain my problem better, in order to add some perspective: My new laptop have two graphic cards. An integrated Intel HD and a GeForce GT 540M. The intel card works most of the time to render SO, because it save battery. When a game is started, then the GeForce is started automatically. This system is called "optimus" by nvidia ( http://www.nvidia.com/object/optimus_technology.html ). The problem is that when I start my application, de opengl driver detected is 2.1 and the vendor is Intel, and I don't know how to switch to the other device.

Finally I found this information. It isn't too useful if you are not using nvidia but I let it to any who could read http://developer.download.nvidia.com/compute/cuda/3_2/toolkit/docs/CUDA_Developer_Guide_for_Optimus_Platforms.pdf

Killrazor
  • 6,856
  • 15
  • 53
  • 69

4 Answers4

23

The simplest solution is to paste this code snippet somewhere in your application. This will tell the Nvidia and AMD drivers to switch to the powerful GPU when your app starts.

// enable optimus!
extern "C" {
    _declspec(dllexport) DWORD NvOptimusEnablement = 1;
    _declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
}

EDIT: add the AMD keyword

manylegged
  • 794
  • 7
  • 14
  • 4
    For the AMD equivalent, see [this](http://stackoverflow.com/questions/17458803/amd-equivalent-to-nvoptimusenablement) question. – fkorsa May 10 '16 at 10:52
9

I am not 100% sure, but I seem to remember that under Windows this is not possible, other than to create a window on a specific screen.

NVidia provided an extension called WGL_NV_gpu_affinity. I'm not sure if this is still available and whether it works as you would like.

Edit:

I see that similar information is already provided in another thread, with an additonal link to this PDF. Not a satisfying answer perhaps, but at least some info.

Community
  • 1
  • 1
Bart
  • 19,692
  • 7
  • 68
  • 77
  • 1
    The fact that this extension is called WGL_nv_gpu_affinity, says that it's for windows, it's the linux one (GLX_...) that is missing, I think. But ATI/AMD has a a similar extension called AMD_gpu_association, which has versions for windows (WGL) and linux (GLX). – Christian Rau May 17 '11 at 21:30
  • Of course you are right (I need coffee). Edited my answer, although it's not much of one. :s – Bart May 17 '11 at 21:35
  • I think that select the device (even a software based device) is an option in directX. Maybe it exists that way to select the device in the win32 toolkit. – Killrazor May 18 '11 at 07:37
  • 1
    I just gave a try to `WGL_NV_gpu_affinity` on my brand new Optimus machine, to try to create a GL on NVidia GPU - without success, the extension is not even exposed by the NVidia driver. Worse, as you need to create a GL context to get the WGL function pointers, you first get an Intel context, which clearly knows nothing of NV extensions... – rotoglup Aug 02 '12 at 11:54
  • 2
    The only solution by the moment is to configure the launch options in nvidia panel and assign the correct card. I haven't found any way to select dinamicaly the desired graphic card. – Killrazor Mar 12 '13 at 09:11
  • 4
    wgl_nv_gpu_affinity extension is only available on nvidia Quadro cards driver. – IdanB Sep 22 '14 at 10:38
2

Go to Nvidia Control Panel > Manage 3d settings > select preferred graphics processor. By default you can see auto-select. Change it to your desired GPU.

veerendra
  • 83
  • 7
  • 1
    Your answer is appropriate for an end-user but not so much for a developer. However it's still good when testing, thanks. – legends2k Sep 08 '17 at 17:46
1

you should use WGL_NV_gpu_affinity extension to programming with multiple GPUs with OpenGL. (in case, NVIDIA card). But it is only supported on QUADRO series. So unfortunately you can't select rendering graphic card on your system.