Something Really Weird with ChoosePixelFormat

Started by
2 comments, last by HappySnapper 22 years, 2 months ago
This is going to sound weird but here is my problem. I''ve recently come across problems with ChoosePixelFormat which has definitely led me to believe there is a bug with this API function. Is ChoosePixelFormat dependent on OpenGL? Msdn library says that it''s an OpenGL SDK function. I finally trapped the error which is that ChoosePixelFormat always returns zero. I compiled NeHe''s lesson one and it was fine. I commented out all of the code that wasn''t related to creating the window, the HDC and the RDC. It worked fine until I commented out the line that says hRC = wglCreateContext(hDC) I ran the program and ChoosePixelFormat returned zero. But the line of code I entered just above is two function calls after PixelFormat = ChoosePixelFormat(hDC, &pfd) I thought C was an imperative language (i.e. the code runs line by line and doesn''t continue until a function has been comleted). I''m not compiling in C++ mode (i.e. my file extention is .c not .cpp). Is it actually possible at compile time for bugs to come up like this? I am seriously baffled! Please Help! Anything would be appreciated. Thanx Andrew McNab
Advertisement
You need the DC and RC to render something in a Win32 window, when you comment this line out it won''T work, because there is no Context.

C/C++ ist not translatet at once HTML ist interpreted line by line I think
That''s just the thing there is a device context. I have the line

hDC = GetDC(hWND);

then

if(hDC)
{
PixelFormat=ChoosePixelFormat(hDC,&pfd);
}

like this, PixelFormat is always zero but if I have

if(hDC)
{
PixelFormat=ChoosePixelFormat(hDC, &pfd);
hRC=wglCreateContext(hDC);
}

then PixelFormat is a valid pixel format to use. This is why I''m seriously baffled. I know there are a lot of bugs with the VC6 compiler but is this one of them? It''s almost like the program, at runtime, knows what the next line of code is or the next couple of lines or something. The code above has valid window handles and a valid PFD. I''ve got service pack 5 for VC6.

How about using the GetLastError() and FormatMessage() functions to try and track down why ChoosePixelFormat() failed.

More details of the functions are in MSDN.

This topic is closed to new replies.

Advertisement