I used the following code to test the SetPixelFormat function in windows API. Although I choose the pixel format without the PFD_SUPPORT_OPENGL flag specificly, openGL commands can still be executed successfully, which means I can see the figure OpenGL drawed.
int idx = 1;
while( true){
++idx;
if (idx > 100){
MessageBox(NULL, "idx > 100", "msg", MB_OK);
break;
}
DescribePixelFormat(hDC, idx, pfd.nSize, &pfd);
if ((pfd.dwFlags & PFD_SUPPORT_OPENGL))
continue;
if (SetPixelFormat(hDC, idx, NULL)){
break;
}
}
Anybody can explain this problem? Thank you. If you need all the code files, please email me.
First, it doesn’t make any sense to set a pixelformat if you don’t want to use OpenGL.
Is there any format without PFD_SUPPORT_OPENGL at all?
Which implementation is that? What does glGetString(GL_VENDOR) return?
Second, you skipped idx == 1 and you hardcoded an upper limit. You need to use DescribePixelFormat() to query the number of available instead of your hardcoded number 100.
You didn’t test if DescribePixelFormat() succeeded. It probably won’t for idx with higher numbers than the available number of pixelformats. The pfd contents are undefined then. SetPixelFormat doesn’t need it anyway except for the record.
Thanks for reply.
I wrote this code just for testing.
glGetString(GL_VENDOR) returns “ATI Technologies Inc.” when I choose hardware acceleration, and it returns “Microsoft Corporation” when I choose generic implementation.
According to the list, only pixelformats in range [1-4] support OpenGL, but in fact all the ICD implementations can draw OPENGL figures successfully. So I guess maybe PFD_SUPPORT_OPENGL doesn’t tell us anything useful?
Well, looks more like a driver bug in the reported pixelformats to me.
“I wrote this code just for testing.”
There are no excuses for broken code.
Testing the wrong thing leads to even more problems due to the derived wrong assumptions. That could get really expensive.