SetPixelFormat fails the second time it's called

When my application starts, OpenGL is initialized without a problem. But if the display mode is changed, and OpenGL re-created, SetPixelFormat fails. Does anyone have any idea what can be causing this? I’ve tried it without changing the display mode or pixel format, just simply re-creating OpenGL, and it still fails. The DC is valid, plus ChoosePixelFormat works.

It is irrelevant whether the program is in windowed or fullscreen modes, I’ve tried both, and re-creating OpenGL in both modes.

SetPixelFormat can only be called one time for any window. To call it again, you must destroy the window, and create a new window.

That’s what I do. When the screen mode is changed, I destroy the entire window and recreate it, and recreate OpenGL from scratch. SetPixelFormat still fails.

If you are not referencing the old DC by mistake, and you properly closed the RC before destroying the old DC, and SetPixelFormat fails to work with the new DC, then I’m at a total loss. Sorry.

Might want to check the error Windows is returning too.

DFrey: How? The function returns a boolean value. Does Windows keep an internal error log or something?

Windows keeps track of the last error that was reported. Use GetLastError() to get the error code, then use FormatMessage(…) to turn the code into something readable.

[This message has been edited by DFrey (edited 02-14-2001).]

OK, I just now did that. Well, FormatMessage doesn’t work for all error codes including this one, so I got GetLastError()'s value and looked it up in MSDN’s error look-up table. It’s ERROR_ALREADY_EXISTS (183). But I called MakeCurrent with null parameters, deleted the OpenGL context, released the DC, destroyed the window, and unregistered the window class. I then remade them all. Nothing still exists! <pulls out hair>

[This message has been edited by CGameProgrammer (edited 02-14-2001).]

Ha ha, I found out what the error was. My OpenGL class is derived from a Renderer class, since my engine supports OpenGL, Direct3D, and software. And I knew constructors were called for every class and parent class (i.e. called OpenGL::OpenGL() and Renderer::Renderer() would automatically be called first), so I naturally assumed the same was true of the destructors. But it apparently isn’t; I needed to make Renderer::~Renderer() virtual. Now it works