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.
31 static int Width
= 400, Height
= 400;
33 static float Xtrans
= 0, Ytrans
= 0;
34 static float Step
= 0.125;
44 static int Mode
= POINTS
;
50 /* See the OpenGL Programming Guide, Appendix H, "OpenGL Correctness Tips"
51 * for information about the 0.375 translation factor.
53 float tx
= 0.375, ty
= 0.375;
56 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
59 glTranslatef(tx
+ Xtrans
, ty
+ Ytrans
, 0);
63 for (j
= 0; j
< Height
; j
+= 2) {
64 for (i
= 0; i
< Width
; i
+= 2) {
70 else if (Mode
== HLINES
) {
72 for (i
= 0; i
< Height
; i
+= 2) {
78 else if (Mode
== VLINES
) {
80 for (i
= 0; i
< Width
; i
+= 2) {
82 glVertex2f(i
, Height
);
86 else if (Mode
== QUADS
) {
88 for (j
= 0; j
< Height
; j
+= 4) {
89 for (i
= 0; i
< Width
; i
+= 4) {
91 glVertex2f(i
+ 3, j
);
92 glVertex2f(i
+ 3, j
+ 3);
106 Reshape(int width
, int height
)
110 glViewport(0, 0, width
, height
);
111 glMatrixMode(GL_PROJECTION
);
113 glOrtho(0, width
, 0, height
, -1, 1);
114 glMatrixMode(GL_MODELVIEW
);
120 Key(unsigned char key
, int x
, int y
)
127 Mode
= (Mode
+ 1) % NUM_MODES
;
132 printf("Translation: %f, %f\n", Xtrans
, Ytrans
);
135 glutDestroyWindow(Win
);
144 SpecialKey(int key
, int x
, int y
)
163 printf("Translation: %f, %f\n", Xtrans
, Ytrans
);
177 printf(" up/down/left/right - translate by %f\n", Step
);
178 printf(" z - reset translation to zero\n");
179 printf(" m - change rendering mode (points, hlines, vlines, quads)\n");
180 printf(" Esc - exit\n");
185 main(int argc
, char *argv
[])
187 glutInit(&argc
, argv
);
188 glutInitWindowPosition(0, 0);
189 glutInitWindowSize(Width
, Height
);
190 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
);
191 Win
= glutCreateWindow(argv
[0]);
192 glutReshapeFunc(Reshape
);
193 glutKeyboardFunc(Key
);
194 glutSpecialFunc(SpecialKey
);
195 glutDisplayFunc(Draw
);