PDA

View Full Version : Need help with SetPixelFormat()/PIXELFORMATDESCRIPTOR



12-02-2002, 02:16 PM
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. http://www.opengl.org/discussion_boards/ubb/smile.gif

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;
}

Nick Nougat
12-02-2002, 07:15 PM
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

12-03-2002, 03:01 AM
Thanks Nick, that worked. http://www.opengl.org/discussion_boards/ubb/biggrin.gif

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.