2 * Test the GL_PERSPECTIVE_CORRECTION_HINT setting and its effect on
5 * Press 'i' to toggle between GL_NICEST/GL_FASTEST/GL_DONT_CARE.
7 * Depending on the driver, the hint may make a difference, or not.
16 static GLenum PerspHint
= GL_DONT_CARE
;
22 GLubyte image
[256][256][4];
24 for (i
= 0; i
< 256; i
++) {
25 for (j
= 0; j
< 256; j
++) {
32 glTexImage2D(GL_TEXTURE_2D
, 0, 4, 256, 256, 0,
33 GL_RGBA
, GL_UNSIGNED_BYTE
, image
);
34 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
35 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
36 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
37 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
38 glTexEnvf(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_DECAL
);
40 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
49 printf("hint = GL_NICEST\n");
52 printf("hint = GL_FASTEST\n");
55 printf("hint = GL_DONT_CARE\n");
61 glClear(GL_COLOR_BUFFER_BIT
);
65 /* exercise perspective interpolation */
66 glColor3f(0.0, 0.0, 0.0); glVertex3f(-1.0, -1.0, -1.0);
67 glColor3f(0.0, 0.0, 0.0); glVertex3f(-1.0, 1.0, -1.0);
68 glColor3f(0.0, 1.0, 0.0); glVertex3f( 7.0, 1.0, -7.0);
69 glColor3f(0.0, 1.0, 0.0); glVertex3f( 7.0, -1.0, -7.0);
71 /* stripe of linear interpolation */
72 glColor3f(0.0, 0.0, 0.0); glVertex3f(-1.0, -0.1, -1.001);
73 glColor3f(0.0, 0.0, 0.0); glVertex3f(-1.0, 0.1, -1.001);
74 glColor3f(0.0, 1.0, 0.0); glVertex3f( 1.0, 0.1, -1.001);
75 glColor3f(0.0, 1.0, 0.0); glVertex3f( 1.0, -0.1, -1.001);
78 glEnable(GL_TEXTURE_2D
);
80 glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, 0.0, -1.0);
81 glTexCoord2f(0.0, 1.0); glVertex3f(-1.0, 1.0, -1.0);
82 glTexCoord2f(1.0, 1.0); glVertex3f( 5.0, 1.0, -7.0);
83 glTexCoord2f(1.0, 0.0); glVertex3f( 5.0, 0.0, -7.0);
85 glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, -1.0, -1.001);
86 glTexCoord2f(0.0, 1.0); glVertex3f(-1.0, 0.0, -1.001);
87 glTexCoord2f(1.0, 1.0); glVertex3f( 1.0, 0.0, -1.001);
88 glTexCoord2f(1.0, 0.0); glVertex3f( 1.0, -1.0, -1.001);
99 glViewport(0, 0, w
, h
);
100 glMatrixMode(GL_PROJECTION
);
102 gluPerspective(90.0, (GLfloat
) w
/ h
, 1.0, 300.0);
103 glMatrixMode(GL_MODELVIEW
);
109 key(unsigned char k
, int x
, int y
)
112 case 27: /* Escape */
116 if (PerspHint
== GL_FASTEST
)
117 PerspHint
= GL_NICEST
;
118 else if (PerspHint
== GL_NICEST
)
119 PerspHint
= GL_DONT_CARE
;
121 PerspHint
= GL_FASTEST
;
122 glHint(GL_PERSPECTIVE_CORRECTION_HINT
, PerspHint
);
132 main(int argc
, char** argv
)
134 glutInit(&argc
, argv
);
135 glutInitDisplayMode (GLUT_SINGLE
| GLUT_RGB
);
136 glutInitWindowSize (500, 500);
137 glutCreateWindow (argv
[0]);
138 glutReshapeFunc (reshape
);
139 glutDisplayFunc(display
);
140 glutKeyboardFunc(key
);
142 printf("Main quad: perspective projection\n");
143 printf("Middle stripe: linear interpolation\n");
144 printf("Press 'i' to toggle interpolation hint\n");