Practice contradicts MSDN document about PixelFormat?

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.

I got a full list of the pixelformats supported on my machine(Windows XP SP2 + ATI Radeon 9550) using the pixelformat functions:
Index Type SUPPORT_OPENGL
1 ICD TRUE
2 ICD TRUE
3 ICD TRUE
4 ICD TRUE
5 ICD FALSE
6 ICD FALSE
7 ICD FALSE
8 ICD FALSE
9 ICD FALSE
10 ICD FALSE
11 ICD FALSE
12 ICD FALSE
13 ICD FALSE
14 ICD FALSE
15 ICD FALSE
16 ICD FALSE
17 GENERIC TRUE
18 GENERIC TRUE
19 GENERIC TRUE
20 GENERIC TRUE
21 GENERIC TRUE
22 GENERIC TRUE
23 GENERIC TRUE
24 GENERIC TRUE
25 GENERIC TRUE
26 GENERIC TRUE
27 GENERIC TRUE
28 GENERIC TRUE
29 GENERIC TRUE
30 GENERIC TRUE
31 GENERIC TRUE
32 GENERIC TRUE
33 GENERIC TRUE
34 GENERIC TRUE
35 GENERIC TRUE
36 GENERIC TRUE
37 GENERIC TRUE
38 GENERIC TRUE
39 GENERIC TRUE
40 GENERIC TRUE
41 GENERIC TRUE
42 GENERIC TRUE
43 GENERIC TRUE
44 GENERIC TRUE
45 GENERIC TRUE
46 GENERIC TRUE
47 GENERIC TRUE
48 GENERIC TRUE
49 GENERIC TRUE
50 GENERIC TRUE
51 GENERIC TRUE
52 GENERIC TRUE

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. :wink:
Testing the wrong thing leads to even more problems due to the derived wrong assumptions. That could get really expensive.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.