View Full Version : SetPixelFormat fails the second time it's called
02-11-2001, 05: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.
02-11-2001, 06: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.
02-11-2001, 07: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.
02-12-2001, 03: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
02-12-2001, 03:11 AM
Might want to check the error Windows is returning too.
02-14-2001, 02:14 PM
DFrey: How? The function returns a boolean value. Does Windows keep an internal error log or something?
02-14-2001, 02: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).]
02-14-2001, 03: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).]
02-16-2001, 11:59 AM
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
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.