SetPixelFormat Fails

Below is my code. I can’t seem to understand whats wrong with it.

I’m getting a very wierd error number too.
m_GLPixelIndex = 4
errCode = 3221684230 ?

Anyone has an idea ?

bool GL3DView::setFormat()
//HWND hMainWnd = ::GetDesktopWindo();
//HDC hMainDC = ::GetDC(hMainWnd);
HDC hDC = qt_display_dc();

PIXELFORMATDESCRIPTOR pixelDesc = // pfd Tells Windows How We Want Things To Be
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
1, // Version Number
PFD_DRAW_TO_WINDOW | // Format Must Support Window
PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
PFD_DOUBLEBUFFER, // Must Support Double Buffering
PFD_TYPE_RGBA, // Request An RGBA Format
24, // Select Our Color Depth
0, 0, 0, 0, 0, 0, // Color Bits Ignored
0, // No Alpha Buffer
0, // Shift Bit Ignored
0, // No Accumulation Buffer
0, 0, 0, 0, // Accumulation Bits Ignored
16, // 16Bit Z-Buffer (Depth Buffer)
0, // No Stencil Buffer
0, // No Auxiliary Buffer
PFD_MAIN_PLANE, // Main Drawing Layer
0, // Reserved
0, 0, 0 // Layer Masks Ignored

int m_GLPixelIndex = ChoosePixelFormat(hDC,&pixelDesc);

DWORD errCode = GetLastError();
return FALSE;

return TRUE;

You could try to know what is in the pixel format to see if the format index sounds reasonnable (and matches your request) :


Add this line after the ChoosePixelFormat call and look at which fields of the pixeldesc change.

Some ideas :
are you sure the dc you get is valid?
when do you call this ‘setFormat’ method?
are you sure this method is called only once?
are you sure qt does not use SetPixelFormat itself (MSDN states that SetPixelFormat is allowed only once per window)?
also, SetPixelFormat must be called before creating the rendering context

hope this helps

I know QT runs setFormat …

I was trying to override without having to reimplement the class …

Is there a way to release it then set it again ?

Destroy and recreate the window, then call SetPixelFormat again.