Weird thing with DescribePixelFormat

Does anyone have an idea why I have to call a GL function before I can get the number of pixel formats supported. In the following code, if I remove glLoadIdentity() (and do a Rebuild All), DescribePixelFormat returns 0. I thought this could be an ICD problem but I tried it on a G400 and a GeForce2 and I got the same problem.

int APIENTRY WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
MSG msg;

hDC = GetDC(NULL);	

// Any GL function...

int nFormatCount = DescribePixelFormat (hDC, 1, 0, NULL);

return msg.wParam;


If I recall correctly, you have to set the pixel format before you can describe it. If you dont set it explicity and then begin issuing commands, I believe it will pick a default format for you. Try using ChoosePixelFormat and SetPixelFormat before you do the describe. These functions are documented in the Win API.

Heh - I think I’ve seen this.

It’s a linker problem. Your OGL call is doing nothing - you don’t have an RC selected so it’ll just fail. But unless you have an OGL function somewhere in your program, the MSVC linker doesn’t link against the OpenGL import lib/dll.

Now, the WGL functions require that your app is linked to OpenGL, and assume that you’re already doing so - otherwise why would you want to call WGL? It doesn’t load the dll itself, so in your case it just fails.

Don’t ask how long it took me to track that one down…

MikeC :
I came to the same conclusion and you confirmed it, thanks ! But there is got to be a way around it. DX can do it so why can’t GL do it. Let me explain : I’m trying to get the number of OGL drivers before any window creation. DX has a function for that :