1 /* Test GL_TEXTURE_BASE_LEVEL and GL_TEXTURE_MAX_LEVEL
7 /* Copyright (c) Mark J. Kilgard, 1994. */
10 * (c) Copyright 1993, Silicon Graphics, Inc.
12 * Permission to use, copy, modify, and distribute this software for
13 * any purpose and without fee is hereby granted, provided that the above
14 * copyright notice appear in all copies and that both the copyright notice
15 * and this permission notice appear in supporting documentation, and that
16 * the name of Silicon Graphics, Inc. not be used in advertising
17 * or publicity pertaining to distribution of the software without specific,
18 * written prior permission.
20 * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
21 * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
22 * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
23 * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
24 * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
25 * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
26 * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
27 * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
28 * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
29 * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
30 * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
31 * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
33 * US Government Users Restricted Rights
34 * Use, duplication, or disclosure by the Government is subject to
35 * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
36 * (c)(1)(ii) of the Rights in Technical Data and Computer Software
37 * clause at DFARS 252.227-7013 and/or in similar or successor
38 * clauses in the FAR or the DOD or NASA FAR Supplement.
39 * Unpublished-- rights reserved under the copyright laws of the
40 * United States. Contractor/manufacturer is Silicon Graphics,
41 * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
43 * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
46 * This program demonstrates using mipmaps for texture maps.
47 * To overtly show the effect of mipmaps, each mipmap reduction
48 * level has a solidly colored, contrasting texture image.
49 * Thus, the quadrilateral which is drawn is drawn with several
57 static GLint BaseLevel
= 0, MaxLevel
= 8;
58 static GLfloat MinLod
= -1, MaxLod
= 9;
59 static GLfloat LodBias
= 0.0;
60 static GLboolean NearestFilter
= GL_TRUE
;
71 NearestFilter
= GL_TRUE
;
75 static void MakeImage(int level
, int width
, int height
, const GLubyte color
[4])
77 const int makeStripes
= 0;
78 GLubyte img
[256*256*3];
80 for (i
= 0; i
< height
; i
++) {
81 for (j
= 0; j
< width
; j
++) {
82 int k
= (i
* width
+ j
) * 3;
83 int p
= (i
/8) & makeStripes
;
85 img
[k
+ 0] = color
[0];
86 img
[k
+ 1] = color
[1];
87 img
[k
+ 2] = color
[2];
97 glTexImage2D(GL_TEXTURE_2D
, level
, GL_RGB
, width
, height
, 0,
98 GL_RGB
, GL_UNSIGNED_BYTE
, img
);
102 static void makeImages(void)
104 static const GLubyte colors
[8][3] = {
116 for (i
= 0; i
< 8; i
++) {
117 MakeImage(i
, sz
, sz
, colors
[i
]);
122 static void myinit(void)
126 glEnable(GL_DEPTH_TEST
);
127 glDepthFunc(GL_LESS
);
128 glShadeModel(GL_FLAT
);
130 glTranslatef(0.0, 0.0, -3.6);
132 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
134 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
135 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
136 glTexEnvf(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_DECAL
);
137 glEnable(GL_TEXTURE_2D
);
140 static void display(void)
143 printf("BASE_LEVEL=%d MAX_LEVEL=%d MIN_LOD=%.2g MAX_LOD=%.2g Bias=%.2g Filter=%s\n",
144 BaseLevel
, MaxLevel
, MinLod
, MaxLod
, LodBias
,
145 NearestFilter
? "NEAREST" : "LINEAR");
146 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_BASE_LEVEL
, BaseLevel
);
147 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAX_LEVEL
, MaxLevel
);
149 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_LOD
, MinLod
);
150 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAX_LOD
, MaxLod
);
153 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
154 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
,
155 GL_NEAREST_MIPMAP_NEAREST
);
158 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
159 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
,
160 GL_LINEAR_MIPMAP_LINEAR
);
163 glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT
, GL_TEXTURE_LOD_BIAS_EXT
, LodBias
);
165 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
167 glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0);
168 glTexCoord2f(0.0, tcm
); glVertex3f(-2.0, 1.0, 0.0);
169 glTexCoord2f(tcm
, tcm
); glVertex3f(3000.0, 1.0, -6000.0);
170 glTexCoord2f(tcm
, 0.0); glVertex3f(3000.0, -1.0, -6000.0);
175 static void myReshape(int w
, int h
)
177 glViewport(0, 0, w
, h
);
178 glMatrixMode(GL_PROJECTION
);
180 gluPerspective(60.0, 1.0*(GLfloat
)w
/(GLfloat
)h
, 1.0, 30000.0);
181 glMatrixMode(GL_MODELVIEW
);
186 key(unsigned char k
, int x
, int y
)
230 NearestFilter
= !NearestFilter
;
235 case 27: /* Escape */
245 static void usage(void)
248 printf(" b/B decrease/increase GL_TEXTURE_BASE_LEVEL\n");
249 printf(" m/M decrease/increase GL_TEXTURE_MAX_LEVEL\n");
250 printf(" n/N decrease/increase GL_TEXTURE_MIN_LOD\n");
251 printf(" x/X decrease/increase GL_TEXTURE_MAX_LOD\n");
252 printf(" l/L decrease/increase GL_TEXTURE_LOD_BIAS\n");
253 printf(" f toggle nearest/linear filtering\n");
254 printf(" SPACE reset values\n");
258 int main(int argc
, char** argv
)
260 glutInit(&argc
, argv
);
261 glutInitDisplayMode (GLUT_SINGLE
| GLUT_RGB
| GLUT_DEPTH
);
262 glutInitWindowSize (600, 600);
263 glutCreateWindow (argv
[0]);
266 glutReshapeFunc (myReshape
);
267 glutDisplayFunc(display
);
268 glutKeyboardFunc(key
);
271 return 0; /* ANSI C requires main to return int. */