PDA

View Full Version : SetPixelFormat fails the second time it's called



CGameProgrammer
02-11-2001, 06:43 PM
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.

DFrey
02-11-2001, 07:48 PM
SetPixelFormat can only be called one time for any window. To call it again, you must destroy the window, and create a new window.

CGameProgrammer
02-11-2001, 08:41 PM
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.

DFrey
02-12-2001, 04:09 AM
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. http://www.opengl.org/discussion_boards/ubb/frown.gif

DFrey
02-12-2001, 04:11 AM
Might want to check the error Windows is returning too.

CGameProgrammer
02-14-2001, 03:14 PM
DFrey: How? The function returns a boolean value. Does Windows keep an internal error log or something?

DFrey
02-14-2001, 03:31 PM
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).]

CGameProgrammer
02-14-2001, 04:55 PM
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).]

CGameProgrammer
02-16-2001, 12:59 PM
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 http://www.opengl.org/discussion_boards/ubb/smile.gif