Need help with SetPixelFormat()/PIXELFORMATDESCRIPTOR

I’m new to OpenGL programming and I’m running into a problem after following the example from NeHe’s page on creating a blank OpenGL window. After compiling and linking my program successfully, when I run the executable, I get an error saying “Can’t Set the PixelFormat”. I’m guessing that if anyone can help me, they’ll need the source to do so. Here’s the descriptor as well as the call to SetPixelFormat.

Thanks in advance.

static PIXELFORMATDESCRIPTOR pfd=
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
bits,
0, 0, 0, 0, 0, 0,
0,
0,
0,
0, 0, 0, 0,
16,
0,
0,
PFD_MAIN_PLANE,
0,
0, 0, 0
};

if(!SetPixelFormat(hDC,PixelFormat,&pfd)))
{
KillGLWindow();
MessageBox(NULL,“Can’t Set The PixelFormat.”,“ERROR”,MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}

Maybe you’re missing a call to

PixelFormat = ChoosePixelFormat(m_hDC, &pfd);
if(!PixelFormat)
   Error

before you try to set the pixel format? Or did you just leav it out of the post?
The format descriptor looks OK to me.

If in doubt, call ::GetLastError() to see what went wrong.

Nick

Thanks Nick, that worked.

I seemed to have missed that section of code in the tutorial. That would also explain the previous warning I received about using an uninitialized variable.