2 * Test for exact point/line/polygon rasterization, or at least rasterization
3 * that fits the tolerance of the OpenGL spec.
11 * - 'm' to cycle through point, hline, vline and quad drawing
12 * - Use cursor keys to translate coordinates (z to reset)
13 * - Resize window to check for proper rasterization
14 * - Make sure your LCD is running in its native resolution
16 * If translation is (0,0):
17 * a point will be drawn where x%2==0 and y%2==0,
18 * a horizontal line will be drawn where x%2==0,
19 * a vertical line will be drawn where y%2==0,
20 * for quads, pixels will be set where (x%4)!=3 and (y%4)!=3
22 * XXX todo: do glReadPixels and test that the results are what's expected.
23 * Upon failure, iterate over sub-pixel translations to find the ideal offset.
32 static int Width
= 400, Height
= 400;
34 static float Xtrans
= 0, Ytrans
= 0;
35 static float Step
= 0.125;
45 static int Mode
= MODE_POINTS
;
51 /* See the OpenGL Programming Guide, Appendix H, "OpenGL Correctness Tips"
52 * for information about the 0.375 translation factor.
54 float tx
= 0.375, ty
= 0.375;
57 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
60 glTranslatef(tx
+ Xtrans
, ty
+ Ytrans
, 0);
62 if (Mode
== MODE_POINTS
) {
64 for (j
= 0; j
< Height
; j
+= 2) {
65 for (i
= 0; i
< Width
; i
+= 2) {
71 else if (Mode
== MODE_HLINES
) {
73 for (i
= 0; i
< Height
; i
+= 2) {
79 else if (Mode
== MODE_VLINES
) {
81 for (i
= 0; i
< Width
; i
+= 2) {
83 glVertex2f(i
, Height
);
87 else if (Mode
== MODE_QUADS
) {
89 for (j
= 0; j
< Height
; j
+= 4) {
90 for (i
= 0; i
< Width
; i
+= 4) {
92 glVertex2f(i
+ 3, j
);
93 glVertex2f(i
+ 3, j
+ 3);
107 Reshape(int width
, int height
)
111 glViewport(0, 0, width
, height
);
112 glMatrixMode(GL_PROJECTION
);
114 glOrtho(0, width
, 0, height
, -1, 1);
115 glMatrixMode(GL_MODELVIEW
);
121 Key(unsigned char key
, int x
, int y
)
128 Mode
= (Mode
+ 1) % NUM_MODES
;
133 printf("Translation: %f, %f\n", Xtrans
, Ytrans
);
136 glutDestroyWindow(Win
);
145 SpecialKey(int key
, int x
, int y
)
164 printf("Translation: %f, %f\n", Xtrans
, Ytrans
);
178 printf(" up/down/left/right - translate by %f\n", Step
);
179 printf(" z - reset translation to zero\n");
180 printf(" m - change rendering mode (points, hlines, vlines, quads)\n");
181 printf(" Esc - exit\n");
186 main(int argc
, char *argv
[])
188 glutInit(&argc
, argv
);
189 glutInitWindowPosition(0, 0);
190 glutInitWindowSize(Width
, Height
);
191 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
);
192 Win
= glutCreateWindow(argv
[0]);
194 glutReshapeFunc(Reshape
);
195 glutKeyboardFunc(Key
);
196 glutSpecialFunc(SpecialKey
);
197 glutDisplayFunc(Draw
);