2
* Test minification vs. magnification filtering.
3
* Draw two quads with different filtering modes:
5
* +--------------------------+ +--------------------------+
6
* | MagFilter = GL_LINEAR | | MagFilter = GL_LINEAR |
7
* | MinFilter = GL_LINEAR | | MinFilter = GL_NEAREST |
8
* +--------------------------+ +--------------------------+
10
* They should look different when the quad is smaller than the level 0
11
* texture size (when minifying).
23
static GLint Width = 1000, Height = 500;
26
static GLint TexWidth = 256, TexHeight = 256;
27
static GLfloat Zpos = 5;
28
static GLboolean MipMap = 0*GL_TRUE;
29
static GLboolean LinearFilter = GL_TRUE;
38
glClear( GL_COLOR_BUFFER_BIT );
40
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
42
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
45
glTranslatef(-1.5, 0, -Zpos);
47
glTexCoord2f(0, 0); glVertex2f(-w, -h);
48
glTexCoord2f(1, 0); glVertex2f( w, -h);
49
glTexCoord2f(1, 1); glVertex2f( w, h);
50
glTexCoord2f(0, 1); glVertex2f(-w, h);
54
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
57
glTranslatef(1.5, 0, -Zpos);
59
glTexCoord2f(0, 0); glVertex2f(-w, -h);
60
glTexCoord2f(1, 0); glVertex2f( w, -h);
61
glTexCoord2f(1, 1); glVertex2f( w, h);
62
glTexCoord2f(0, 1); glVertex2f(-w, h);
73
GLubyte color[10][4] = {
87
printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
88
printf("Left quad should be linear filtered and right should be nearest filtered.\n");
89
printf("Press z/Z to change quad distance.\n");
91
texImage = (GLubyte*) malloc(4 * TexWidth * TexHeight * sizeof(GLubyte));
96
GLint w = TexWidth, h = TexHeight;
100
for (i = 0; i < h; i++) {
101
for (j = 0;j < w; j++) {
102
if (w==1 || h==1 || (((i / 2) ^ (j / 2)) & 1)) {
104
texImage[(i*w+j) * 4 + 0] = 255;
105
texImage[(i*w+j) * 4 + 1] = 255;
106
texImage[(i*w+j) * 4 + 2] = 255;
107
texImage[(i*w+j) * 4 + 3] = 255;
110
texImage[(i*w+j) * 4 + 0] = color[level][0] * 255;
111
texImage[(i*w+j) * 4 + 1] = color[level][1] * 255;
112
texImage[(i*w+j) * 4 + 2] = color[level][2] * 255;
113
texImage[(i*w+j) * 4 + 3] = color[level][3] * 255;
118
glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA8, w, h, 0,
119
GL_RGBA, GL_UNSIGNED_BYTE, texImage);
121
printf("Texture level %d: %d x %d\n", level, w, h);
125
if (w == 1 && h == 1)
137
glClearColor(0.25, 0.25, 0.25, 1.0);
138
glEnable(GL_TEXTURE_2D);
140
glViewport(0, 0, Width, Height);
146
Reshape(int width, int height)
148
float ar = (float) width /height;
151
glViewport(0, 0, width, height);
152
glMatrixMode(GL_PROJECTION);
154
glFrustum(-ar, ar, -1.0, 1.0, 5.0, 2500.0);
155
glMatrixMode(GL_MODELVIEW);
157
glTranslatef(0.0, 0.0, -15.0);
162
Key(unsigned char key, int x, int y)
174
LinearFilter = !LinearFilter;
185
main(int argc, char *argv[])
187
glutInit(&argc, argv);
188
glutInitWindowPosition(0, 0);
189
glutInitWindowSize(Width, Height);
190
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
191
glutCreateWindow(argv[0]);
193
glutReshapeFunc(Reshape);
194
glutKeyboardFunc(Key);
195
glutDisplayFunc(redraw);