2 * GL_EXT_texture_lod_bias demo
4 * Thanks to Michael Vance for implementing this extension in Mesa.
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.
36 #include "../util/readtex.c" /* I know, this is a hack. */
38 #define TEXTURE_FILE "../images/girl.rgb"
40 static GLfloat Xrot
= 0, Yrot
= -30, Zrot
= 0;
41 static GLboolean Anim
= GL_TRUE
;
42 static GLint Bias
= 0, BiasStepSign
= +1; /* ints avoid fp precision problem */
43 static GLint BiasMin
= -200, BiasMax
= 500;
48 PrintString(const char *s
)
51 glutBitmapCharacter(GLUT_BITMAP_8_BY_13
, (int) *s
);
56 static void Idle( void )
58 static int lastTime
= 0;
59 int time
= glutGet(GLUT_ELAPSED_TIME
);
64 else if (time
- lastTime
< 10)
67 step
= (time
- lastTime
) / 10 * BiasStepSign
;
75 else if (Bias
> BiasMax
) {
84 static void Display( void )
88 glClear( GL_COLOR_BUFFER_BIT
);
90 glMatrixMode( GL_PROJECTION
);
92 glOrtho(-1, 1, -1, 1, -1, 1);
93 glMatrixMode( GL_MODELVIEW
);
96 glDisable(GL_TEXTURE_2D
);
98 glRasterPos3f(-0.9, -0.9, 0.0);
99 sprintf(str
, "Texture LOD Bias = %4.1f", Bias
* 0.01);
102 glMatrixMode( GL_PROJECTION
);
104 glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
105 glMatrixMode( GL_MODELVIEW
);
107 glTranslatef( 0.0, 0.0, -8.0 );
110 glRotatef(Xrot
, 1, 0, 0);
111 glRotatef(Yrot
, 0, 1, 0);
112 glRotatef(Zrot
, 0, 0, 1);
114 glEnable(GL_TEXTURE_2D
);
115 glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT
, GL_TEXTURE_LOD_BIAS_EXT
, 0.01 * Bias
);
118 glTexCoord2f(0, 0); glVertex2f(-1, -1);
119 glTexCoord2f(2, 0); glVertex2f( 1, -1);
120 glTexCoord2f(2, 2); glVertex2f( 1, 1);
121 glTexCoord2f(0, 2); glVertex2f(-1, 1);
130 static void Reshape( int width
, int height
)
132 glViewport( 0, 0, width
, height
);
136 static void Key( unsigned char key
, int x
, int y
)
138 const GLfloat step
= 3.0;
169 static void SpecialKey( int key
, int x
, int y
)
171 const GLfloat step
= 3.0;
192 static void Init( void )
194 const char *exten
= (const char *) glGetString(GL_EXTENSIONS
);
195 if (!strstr(exten
, "GL_EXT_texture_lod_bias")) {
196 printf("Sorry, GL_EXT_texture_lod_bias not supported by this renderer.\n");
200 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
201 if (!LoadRGBMipmaps(TEXTURE_FILE
, GL_RGB
)) {
202 printf("Error: could not load texture image %s\n", TEXTURE_FILE
);
206 /* mipmapping required for this extension */
207 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR_MIPMAP_LINEAR
);
208 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
209 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_MODULATE
);
213 int main( int argc
, char *argv
[] )
215 glutInit( &argc
, argv
);
216 glutInitWindowPosition( 0, 0 );
217 glutInitWindowSize( 350, 350 );
218 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
);
219 glutCreateWindow(argv
[0]);
220 glutReshapeFunc( Reshape
);
221 glutKeyboardFunc( Key
);
222 glutSpecialFunc( SpecialKey
);
223 glutDisplayFunc( Display
);