1 /* $Id: anisotropic.c,v 1.1 2001/03/22 15:24:15 gareth Exp $ */
4 * GL_ARB_texture_filter_anisotropic demo
9 * Copyright (C) 2000 Brian Paul All Rights Reserved.
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included
19 * in all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
25 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 /* This is a fairly early version. All it does is draw a couple of
30 * textured quads with different forms of texture filtering. Eventually,
31 * you'll be able to adjust the maximum anisotropy and so on.
39 #define TEXTURE_SIZE 256
40 static GLubyte image
[TEXTURE_SIZE
][TEXTURE_SIZE
][3];
42 static GLfloat repeat
= 1.0;
44 static GLfloat texcoords
[] = {
51 static GLfloat vertices
[] = {
53 -400.0, 400.0, -7000.0,
58 static GLfloat maxAnisotropy
;
61 static void init( void )
65 if ( !glutExtensionSupported( "GL_EXT_texture_filter_anisotropic" ) ) {
66 fprintf( stderr
, "Sorry, this demo requires GL_EXT_texture_filter_anisotropic.\n" );
70 glClearColor( 0.0, 0.0, 0.0, 0.0 );
71 glShadeModel( GL_SMOOTH
);
73 /* Init the vertex arrays.
75 glEnableClientState( GL_VERTEX_ARRAY
);
76 glEnableClientState( GL_TEXTURE_COORD_ARRAY
);
78 glVertexPointer( 3, GL_FLOAT
, 0, vertices
);
79 glTexCoordPointer( 2, GL_FLOAT
, 0, texcoords
);
81 /* Init the texture environment.
83 glEnable( GL_TEXTURE_2D
);
84 glTexEnvi( GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
86 glMatrixMode( GL_TEXTURE
);
87 glScalef( repeat
, repeat
, 0 );
89 glMatrixMode( GL_MODELVIEW
);
91 glGetFloatv( GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT
, &maxAnisotropy
);
92 printf( "Maximum supported anisotropy: %.2f\n", maxAnisotropy
);
94 /* Make the texture image.
96 glPixelStorei( GL_UNPACK_ALIGNMENT
, 1 );
98 for ( i
= 0 ; i
< TEXTURE_SIZE
; i
++ ) {
99 for ( j
= 0 ; j
< TEXTURE_SIZE
; j
++ ) {
100 if ( (i
/4 + j
/4) & 1 ) {
105 image
[i
][j
][0] = 255;
106 image
[i
][j
][1] = 255;
107 image
[i
][j
][2] = 255;
112 gluBuild2DMipmaps( GL_TEXTURE_2D
, GL_RGB
, TEXTURE_SIZE
, TEXTURE_SIZE
,
113 GL_RGB
, GL_UNSIGNED_BYTE
, image
);
116 static void display( void )
120 glClear( GL_COLOR_BUFFER_BIT
);
122 glGetIntegerv( GL_VIEWPORT
, vp
);
126 /* Upper left corner:
128 glViewport( 1, h
+ 1, w
- 2, h
- 2 );
130 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
131 glTexParameterf( GL_TEXTURE_2D
, GL_TEXTURE_MAX_ANISOTROPY_EXT
, maxAnisotropy
);
133 glDrawArrays( GL_TRIANGLE_STRIP
, 0, 4 );
136 /* Upper right corner:
138 glViewport( w
+ 1, h
+ 1, w
- 2, h
- 2 );
140 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR_MIPMAP_NEAREST
);
141 glTexParameterf( GL_TEXTURE_2D
, GL_TEXTURE_MAX_ANISOTROPY_EXT
, maxAnisotropy
);
143 glDrawArrays( GL_TRIANGLE_STRIP
, 0, 4 );
146 /* Lower left corner:
148 glViewport( 1, 1, w
- 2, h
- 2 );
150 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST_MIPMAP_LINEAR
);
151 glTexParameterf( GL_TEXTURE_2D
, GL_TEXTURE_MAX_ANISOTROPY_EXT
, maxAnisotropy
);
153 glDrawArrays( GL_TRIANGLE_STRIP
, 0, 4 );
156 /* Lower right corner:
158 glViewport( w
+ 1, 1, w
- 2, h
- 2 );
160 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR_MIPMAP_LINEAR
);
161 glTexParameterf( GL_TEXTURE_2D
, GL_TEXTURE_MAX_ANISOTROPY_EXT
, maxAnisotropy
);
163 glDrawArrays( GL_TRIANGLE_STRIP
, 0, 4 );
166 glViewport( vp
[0], vp
[1], vp
[2], vp
[3] );
171 static void reshape( int w
, int h
)
173 glViewport( 0, 0, (GLsizei
) w
, (GLsizei
) h
);
175 glMatrixMode( GL_PROJECTION
);
177 glFrustum( -1.0, 1.0, -1.0, 1.0, 10.0, 10000.0 );
179 glMatrixMode( GL_MODELVIEW
);
181 glTranslatef( 0.0, 0.0, -10.0 );
184 static void key( unsigned char key
, int x
, int y
)
196 static void usage( void )
201 int main( int argc
, char **argv
)
203 glutInit( &argc
, argv
);
204 glutInitDisplayMode( GLUT_DOUBLE
| GLUT_RGB
);
205 glutInitWindowSize( 600, 300 );
206 glutInitWindowPosition( 0, 0 );
207 glutCreateWindow( "Anisotropic Texture Filter Demo" );
211 glutDisplayFunc( display
);
212 glutReshapeFunc( reshape
);
213 glutKeyboardFunc( key
);