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
56 static GLint BaseLevel
= 0, MaxLevel
= 8;
57 static GLfloat MinLod
= -1, MaxLod
= 9;
58 static GLfloat LodBias
= 0.0;
59 static GLboolean NearestFilter
= GL_TRUE
;
62 static void MakeImage(int level
, int width
, int height
, const GLubyte color
[4])
64 const int makeStripes
= 0;
65 GLubyte img
[256*256*3];
67 for (i
= 0; i
< height
; i
++) {
68 for (j
= 0; j
< width
; j
++) {
69 int k
= (i
* width
+ j
) * 3;
70 int p
= (i
/8) & makeStripes
;
72 img
[k
+ 0] = color
[0];
73 img
[k
+ 1] = color
[1];
74 img
[k
+ 2] = color
[2];
84 glTexImage2D(GL_TEXTURE_2D
, level
, GL_RGB
, width
, height
, 0,
85 GL_RGB
, GL_UNSIGNED_BYTE
, img
);
89 static void makeImages(void)
91 static const GLubyte colors
[8][3] = {
103 for (i
= 0; i
< 8; i
++) {
104 MakeImage(i
, sz
, sz
, colors
[i
]);
109 static void myinit(void)
111 glEnable(GL_DEPTH_TEST
);
112 glDepthFunc(GL_LESS
);
113 glShadeModel(GL_FLAT
);
115 glTranslatef(0.0, 0.0, -3.6);
117 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
119 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
120 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
121 glTexEnvf(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_DECAL
);
122 glEnable(GL_TEXTURE_2D
);
125 static void display(void)
128 printf("BASE_LEVEL = %d MAX_LEVEL = %d MIN_LOD = %f MAX_LOD = %f Bias = %.2g filter = %s\n",
129 BaseLevel
, MaxLevel
, MinLod
, MaxLod
, LodBias
,
130 NearestFilter
? "NEAREST" : "LINEAR");
131 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_BASE_LEVEL
, BaseLevel
);
132 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAX_LEVEL
, MaxLevel
);
134 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_LOD
, MinLod
);
135 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAX_LOD
, MaxLod
);
138 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
139 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
,
140 GL_NEAREST_MIPMAP_NEAREST
);
143 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
144 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
,
145 GL_LINEAR_MIPMAP_LINEAR
);
148 glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT
, GL_TEXTURE_LOD_BIAS_EXT
, LodBias
);
150 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
152 glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0);
153 glTexCoord2f(0.0, tcm
); glVertex3f(-2.0, 1.0, 0.0);
154 glTexCoord2f(tcm
, tcm
); glVertex3f(3000.0, 1.0, -6000.0);
155 glTexCoord2f(tcm
, 0.0); glVertex3f(3000.0, -1.0, -6000.0);
160 static void myReshape(int w
, int h
)
162 glViewport(0, 0, w
, h
);
163 glMatrixMode(GL_PROJECTION
);
165 gluPerspective(60.0, 1.0*(GLfloat
)w
/(GLfloat
)h
, 1.0, 30000.0);
166 glMatrixMode(GL_MODELVIEW
);
171 key(unsigned char k
, int x
, int y
)
215 NearestFilter
= !NearestFilter
;
217 case 27: /* Escape */
227 static void usage(void)
230 printf(" b/B decrease/increase GL_TEXTURE_BASE_LEVEL\n");
231 printf(" m/M decrease/increase GL_TEXTURE_MAX_LEVEL\n");
232 printf(" n/N decrease/increase GL_TEXTURE_MIN_LOD\n");
233 printf(" x/X decrease/increase GL_TEXTURE_MAX_LOD\n");
234 printf(" l/L decrease/increase GL_TEXTURE_LOD_BIAS\n");
235 printf(" f toggle nearest/linear filtering\n");
239 int main(int argc
, char** argv
)
241 glutInit(&argc
, argv
);
242 glutInitDisplayMode (GLUT_SINGLE
| GLUT_RGB
| GLUT_DEPTH
);
243 glutInitWindowSize (600, 600);
244 glutCreateWindow (argv
[0]);
246 glutReshapeFunc (myReshape
);
247 glutDisplayFunc(display
);
248 glutKeyboardFunc(key
);
251 return 0; /* ANSI C requires main to return int. */