Something Really Weird with ChoosePixelFormat
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
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
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement