PIXELFORMATDESCRIPTOR problems

I am using Visual C++ code that ran perfectly on an Alpha platform. I have ported the code over to an Intel-based platform and now I get the following message when I run the program:

“Couldnt Set Pixel Format”

This message didn’t appear when the program was run on the Alpha. I have gone in to the debugger and it tells me that the “Best Matching Pixel Format Index is 5” but then it can’t set that format. Not knowing what else to try to remove this message I have gone in to my code and changed the PIXELFORMATDESCRIPTOR settings so they match up with the Pixel Format Index specified as the best match but the error still remains. This is all new to me so I really don’t know what else to do.

Um, you should check to see that the device context is defined before actually setting it. That’s about the only thing i can say right now. Put up the code with you defining the PIXELFORMATDESCRIPTOR instance and the code for you setting it up, and we’ll see where we can go from there .

  • Halcyon

Try using this code for your project just to see if it works out:

//Describes pixel format
PIXELFORMATDESCRIPTOR pfd;
//stores pixel format type
int pixelFormat;

//Fill pfd
pfd.bReserved = 0;
pfd.cAccumAlphaBits = 0;
pfd.cAccumBits = 0;
pfd.cAccumBlueBits = 0;
pfd.cAccumGreenBits = 0;
pfd.cAccumRedBits = 0;
pfd.cAlphaBits = 0;
pfd.cAlphaShift = 0;
pfd.cAuxBuffers = 0;
pfd.cBlueBits = 0;
pfd.cBlueShift = 0;
pfd.cColorBits = 32;
pfd.cDepthBits = 16;
pfd.cGreenBits = 0;
pfd.cGreenShift = 0;
pfd.cRedBits = 0;
pfd.cRedShift = 0;
pfd.cStencilBits = 0;
pfd.dwDamageMask = NULL;
pfd.dwFlags = PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER;
pfd.dwLayerMask = NULL;
pfd.dwVisibleMask = NULL;
pfd.iLayerType = PFD_MAIN_PLANE;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.nSize = sizeof PIXELFORMATDESCRIPTOR;
pfd.nVersion = 1;

//obtain pixel format
pixelFormat = ChoosePixelFormat(hDC,&pfd);

//makes sure pixel format was obtained
if(pixelFormat == NULL){
MessageBox(NULL,“Could no choose pixel format.”,
“Periodic Table of Elements - v1.0”, MB_OK|MB_ICONERROR);
}

//Set pixel format & make sure it was set
if(!SetPixelFormat(hDC,pixelFormat,&pfd)){
MessageBox(NULL,“Could no set pixel format.”,
“Periodic Table of Elements - v1.0”, MB_OK|MB_ICONERROR);
}

This is code i used in my old project, and you can change what the message boxes say and stuff. Good luck.

-Halcyon

I had the same effect some time ago. It seemed to be a driver problem (nvidia, I forgot the revision number, but it was the one before 41.09). However the problem never ever occured after installing v41.09, the latest driver.

One of those older nVidia drivers had a bug in the Pixelformat extension. It took me two days until i gave it up. After installing the latest driver i tried exactly the same stuff again and then it worked.
Blame nVidia :wink:

Jan.

PS: Even their own Demo Program, which showed the Pixelformat extension, crashed on my PC :slight_smile: