Archived

This topic is now archived and is closed to further replies.

Troubles with ChoosePixelFormat()

This topic is 5375 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m a hobbyist programmer who is making a very OOP version of the NeHe GL code in Delphi. Unfortunately my code works flawlessly the first time I run it but it will not run thereafter. I have the problem nailed down to the line of code: PF := ChoosePixelFormat(DC, @pfd); It would look like this in C++: PF = ChoosePixelFormat(DF, &pfd); Well my main concern is that the window compiles and runs the first time. The window should be shutting down completely and not leave any memory leaks. When I run the program again the computer gets to the line where it chooses the pixel format and just breaks from execution. I have had this happen on numerous occasions and even on the NeHe GL basecode. I am running a decent computer with Windows Millenium (my biggest mistake) and the program will compile on other operating systems and run without errors. My biggest question is: is there any way to fix this? I could switch to programming from under Windows XP but I don''t believe my software would work correctly in Windows ME. Any feedback would be appreciated.

Share this post


Link to post
Share on other sites
Make sure you release everything like hdc and stuff when you close the app. Check the Nehe base code and see if you clean up like you should....

Share this post


Link to post
Share on other sites
I removed some of my error checking to simplify it a bit, but here is the essence of it:

procedure TGLBaseWindow.ShutdownWindow;
begin
if Fullscreen then begin
ChangeDisplaySettings(DEVMODE(nil^), 0);
ShowCursor(true);
end;

if RC <> 0 then begin
wglMakeCurrent(0, 0);
wglDeleteContext(RC);

RC := 0;
end;

if (DC <> 0) and (ReleaseDC(hWnd, DC) = 0) then begin
DC := 0;
end;

if (hWnd <> 0) and not DestroyWindow(hWnd) then begin
hWnd := 0;
end;

UnregisterClass(GLBaseWindowClassName, hInstance);
end;

Any ideas what I''m leaving out?

Share this post


Link to post
Share on other sites
Sorry, I can''t help you - but just to hear myself talk... I''ve written OpenGL programs on Windows 95 and when I call ChoosePixelFormat it always runs okay, but in debug mode you can see that some Windows DLLs are throwing 50 to 100 exceptions. This sometimes stalls the window from being created for several seconds. I''ll keep my eye on this thread because it''s always made me suspicious and I''d love to clean it up. You are not alone.

Share this post


Link to post
Share on other sites
Well thanks for the support. I just can''t see why it will choose the pixelformat the first time it is compiled but it will exit entirely without giving me any message the second time. It doesn''t matter if i''m in debug mode or not, it just refuses to work.

Share this post


Link to post
Share on other sites

      PIXELFORMATDESCRIPTOR pfd; 
Sdword pixelformat;

pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); // Set the size of the structure

pfd.nVersion = 1; // Always set this to 1

// Pass in the appropriate OpenGL flags

pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | (DoubleBuffer ? PFD_DOUBLEBUFFER : 0); //or''ing zero does nothing

pfd.dwLayerMask = PFD_MAIN_PLANE; // We want the standard mask (this is ignored anyway)

pfd.iPixelType = PFD_TYPE_RGBA; // We want RGB and Alpha pixel type

pfd.cColorBits = ColorDepth; // Here we use our #define for the color bits
pfd.cDepthBits = DepthBufferDepth; // Depthbits is ignored for RGBA, but we do it anyway

pfd.cAccumBits = AccumulationBufferDepth; // No special bitplanes needed

pfd.cStencilBits = StencilBufferDepth; // We desire no stencil bits

pfd.cAuxBuffers=(unsigned char)NumberOfExtraBuffers;

if((pixelformat=ChoosePixelFormat(WindowDC,&pfd))==FALSE)
{
return false;
}
if(SetPixelFormat(WindowDC,pixelformat,&pfd)==FALSE)
{
return false;
}


That''s the way I do it. Not sure if it''ll help at all, just thought it might be usefull because I''ve never even looked at nehe''s basecode and there could be a fundamental flaw or something in it.

Share this post


Link to post
Share on other sites