PixelFormat failures on Win2K / NT

My app runs on Windows (uses MFC) and provides an MDI (multiple document interface) with up to 6 rendering windows at once. Originally developed on Win95, it has been running on WinNT and now Win2k. The app is a spacecraft simulation (real spacecraft, not a game) and one feature is the “reset” button, that closes all windows, stops the simulation, and then restarts it. Restarting involves reopening and repositioning the windows to the positions set by the user.

Had a bug using WinNT, and fixed it. But just now it’s come back with Win2k. Here it is…

If the application closes all the windows - gl contexts and windows DCs - then reopens windows DCs and tries to query for pixel formats, sometimes the pixel format query will fail. It will return zero pixel formats. The failure is kind of unpredictable, but the probability of failure is very high.

Users with no graphics card (they use the onboard graphics with Intel drivers) in their W2K boxes encounter this problem. Those with graphics cards and drivers do not.

I’ve discovered that the trick is to never give up all the gl contexts. So when the app starts I open a little window, create a gl context, close the window, and keep the gl context until the app actually quits. This works for NT, and for W2K (which is based on “NT Technology”.)

Seems like a combination of WinNT(Win2K), Intel drivers, and giving up all gl contexts.

Does anyone have any info on what this is all about? Has anyone else ever encountered this problem?


I had a similar problem on Win2K and XP when writing a C# wrapper for OpenGL and rendering to bitmap. I could only get a pixel format if I repeated the call to ChoosePixelFormat() after it failed, or (in my final code) inserted a glFlush() immediately before ChoosePixelFormat(). I’ve no idea why this was necessary but it didn’t happen on all machines so is possibly driver-dependent.

One of my futile attempts to get this to work included repeating the GetPixelFormat call a number of times. Never worked. Looked like once a windows DC decided it did not have any pixel formats, it would never change it’s mind!

You definitely destroy the windows?
I believe you can’t set the pixel format of a window more than once, you see.

Are you using CS_OWNDC?

>>>Seems like a combination of WinNT(Win2K), Intel drivers, and giving up all gl contexts.<<<

I have written MDI, SDI and dialog based apps and they all worked on Win98, NT, 2k, XP with Nvidia.

I dont think its your fault. Its probably the Intel drivers. I have had issues with ATI, Matrox but I never tested on Intel.

I’m sure I’ve closed the window, for sure.

While trying to figure this out, I’ve let the window open without a gl context. So the user sees an empty window frame with no rendering. The user can manually close and reopen the window, and often that will work. The DC for that new window will have pixel formats. The thing that’s frustrating is that the failure is not 100%. I don’t know which window will fail, or when, but one will eventually return zero pixel format.

And again the error only occurs if I close ALL the gl contexts. If I never close them all, I can make as many as I want.

[This message has been edited by gstrickler (edited 04-15-2003).]

[This message has been edited by gstrickler (edited 04-15-2003).]

Originally posted by gstrickler:
I’m sure I’ve closed the window, for sure.

Closed the window as in,

or DestoryWindow(HWND)? Only the latter really “closes” the window.

I’m using a subclass of MFC’s CView as my window class. Each time a window is closed, I go through the OnDestroy() method, which calls the CWnd Destroy() method, which calls Destroy() on the window. It’s gone.

[This message has been edited by gstrickler (edited 04-15-2003).]