1 /* Copyright (c) Mark J. Kilgard, 1994. */
3 * (c) Copyright 1993, Silicon Graphics, Inc.
5 * Permission to use, copy, modify, and distribute this software for
6 * any purpose and without fee is hereby granted, provided that the above
7 * copyright notice appear in all copies and that both the copyright notice
8 * and this permission notice appear in supporting documentation, and that
9 * the name of Silicon Graphics, Inc. not be used in advertising
10 * or publicity pertaining to distribution of the software without specific,
11 * written prior permission.
13 * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
14 * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
16 * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
17 * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
18 * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
19 * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
20 * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
21 * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
22 * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
23 * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
24 * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
26 * US Government Users Restricted Rights
27 * Use, duplication, or disclosure by the Government is subject to
28 * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
29 * (c)(1)(ii) of the Rights in Technical Data and Computer Software
30 * clause at DFARS 252.227-7013 and/or in similar or successor
31 * clauses in the FAR or the DOD or NASA FAR Supplement.
32 * Unpublished-- rights reserved under the copyright laws of the
33 * United States. Contractor/manufacturer is Silicon Graphics,
34 * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
36 * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
40 * Test compressed texture mipmaps
42 * Based on mipmap_limits
53 #define SIZE 16 /* not larger then 16 */
55 static GLint BaseLevel
= 0, MaxLevel
;
56 static GLfloat MinLod
, MaxLod
;
57 static GLfloat LodBias
;
58 static GLboolean NearestFilter
;
59 static GLuint texImage
;
68 static struct view views
[] =
71 { 0, 1, "Green, Red" },
72 { 0, 2, "Green, Red, Blue" },
73 { 0, 3, "Green, Red, Blue, Black" },
74 { 0, 4, "Green, Red, Blue, Black, White" },
75 { 1, 4, "Red, Blue, Black, White" },
76 { 2, 4, "Blue, Black, White" },
77 { 3, 4, "Black, White" },
82 { 1, 3, "Red, Blue, Black" },
83 { 1, 2, "Red, Blue" },
84 { 2, 3, "Blue, Black" },
94 MinLod
= views
[View
].minLod
;
95 MaxLod
= views
[View
].maxLod
;
97 NearestFilter
= GL_TRUE
;
104 if (views
[++View
].string
== NULL
)
107 MinLod
= views
[View
].minLod
;
108 MaxLod
= views
[View
].maxLod
;
113 makeImage(int level
, int width
, int height
)
115 GLubyte img
[SIZE
*SIZE
*3];
116 GLubyte color
[5][3] = {
125 for (i
= 0; i
< height
; i
++) {
126 for (j
= 0; j
< width
; j
++) {
127 int k
= (i
* width
+ j
) * 3;
128 img
[k
+ 0] = color
[level
][0];
129 img
[k
+ 1] = color
[level
][1];
130 img
[k
+ 2] = color
[level
][2];
134 glTexImage2D(GL_TEXTURE_2D
, level
,
135 GL_COMPRESSED_RGB_S3TC_DXT1_EXT
,
137 GL_RGB
, GL_UNSIGNED_BYTE
, img
);
146 for (i
= 0, sz
= SIZE
; sz
>= 1; i
++, sz
/= 2) {
147 makeImage(i
, sz
, sz
);
148 printf("Level %d size: %d x %d\n", i
, sz
, sz
);
159 glEnable(GL_DEPTH_TEST
);
160 glDepthFunc(GL_LESS
);
161 glShadeModel(GL_FLAT
);
163 glTranslatef(0.0, 0.0, -3.6);
165 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
166 glGenTextures(1, &texImage
);
167 glBindTexture(GL_TEXTURE_2D
, texImage
);
170 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
171 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
172 glTexEnvf(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_DECAL
);
173 glEnable(GL_TEXTURE_2D
);
181 glBindTexture(GL_TEXTURE_2D
, texImage
);
183 printf("BASE_LEVEL=%d MAX_LEVEL=%d MIN_LOD=%.2g MAX_LOD=%.2g Bias=%.2g Filter=%s\n",
184 BaseLevel
, MaxLevel
, MinLod
, MaxLod
, LodBias
,
185 NearestFilter
? "NEAREST" : "LINEAR");
186 printf("You should see: %s\n", views
[View
].string
);
189 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_BASE_LEVEL
, BaseLevel
);
190 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAX_LEVEL
, MaxLevel
);
192 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_LOD
, MinLod
);
193 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAX_LOD
, MaxLod
);
196 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
197 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
,
198 GL_NEAREST_MIPMAP_NEAREST
);
201 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
202 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
,
203 GL_LINEAR_MIPMAP_LINEAR
);
206 glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT
, GL_TEXTURE_LOD_BIAS_EXT
, LodBias
);
208 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
210 glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0);
211 glTexCoord2f(0.0, tcm
); glVertex3f(-2.0, 1.0, 0.0);
212 glTexCoord2f(tcm
* 3000.0, tcm
); glVertex3f(3000.0, 1.0, -6000.0);
213 glTexCoord2f(tcm
* 3000.0, 0.0); glVertex3f(3000.0, -1.0, -6000.0);
220 myReshape(int w
, int h
)
222 glViewport(0, 0, w
, h
);
223 glMatrixMode(GL_PROJECTION
);
225 gluPerspective(60.0, 1.0*(GLfloat
)w
/(GLfloat
)h
, 1.0, 30000.0);
226 glMatrixMode(GL_MODELVIEW
);
232 key(unsigned char k
, int x
, int y
)
277 NearestFilter
= !NearestFilter
;
283 case 27: /* Escape */
298 printf(" Any Change view\n");
299 printf(" SPACE reset values\n");
304 main(int argc
, char** argv
)
306 glutInit(&argc
, argv
);
307 glutInitDisplayMode (GLUT_SINGLE
| GLUT_RGB
| GLUT_DEPTH
);
308 glutInitWindowSize (600, 600);
309 glutCreateWindow (argv
[0]);
312 glutReshapeFunc (myReshape
);
313 glutDisplayFunc(display
);
314 glutKeyboardFunc(key
);
317 return 0; /* ANSI C requires main to return int. */