PDA

View Full Version : PIXELFORMATDESCTIPTOR problem



sikkiv
04-23-2013, 11:13 AM
Hi everyone,

I'm relatively new to OpenGL programming. I successfully wrote an application with freeGLUT and GLEW displaying some triangles and some textures.
Now I wanted to create an application without freeGLUT.
The problem is that "ChoosePixelFormat()" always returns 0 instead of some matching number.
Here is my PIXELFORMATDESCRIPTOR:


PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
32,
0, 0, 0, 0, 0, 0,
0,
0,
0,
0, 0, 0, 0,
24,
0,
0,
PFD_MAIN_PLANE,
0,
0, 0, 0
};

int matchingPFD;
matchingPFD = ChoosePixelFormat(hdc, &pfd);


I really have no idea what I am doing wrong here so I hope someone can help me out.
For your information I'm using Windows 8 and Visual Studio 2010.

Thanks and greetz
sikkiv

nuclear_bro
04-24-2013, 07:15 AM
At least, as MSDN says, you can call GetLastError() after ChoosePixelFormat() to retrieve something to start with.

tonyo_au
04-24-2013, 06:35 PM
I know you can only call SetPixelFormat once for a window; this may be true for ChoosePixelFormat as well.

Aleksandar
04-25-2013, 02:43 AM
First of all, use PIXELFORMATDESCRIPTOR as a structure, and set parameters by name.
Second, unlike setting pixel format, choosing is not "malicious" operation and you can call it unlimited number of times without any convenience.
Third, what's GetLastError saying?

Try the following form of your setting:

PIXELFORMATDESCRIPTOR pfd ;
memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cDepthBits = 24;
pfd.iLayerType = PFD_MAIN_PLANE;

sikkiv
04-25-2013, 03:33 AM
First thanks for your replies :)

I set the parameters by name and called GetLastError, here is the error message:
"ChoosePixelFormat failed with error 6: the handle is invalid"
So it's clear what I've done wrong, I didn't retrieve the device context properly :whistle:
Now it's working just fine.
I should get more comfortable with the Win32 API I think :D

But thanks to all for the effort.
greetz sikkiv