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.
54 static GLfloat LodBias
= 6.0; /* make smallest miplevel visible */
55 static GLuint texImage
;
63 LodBias
= 6.0; /* make smallest miplevel visible */
67 static void MakeImage(void)
69 const GLubyte color0
[4] = { 0xff, 0x80, 0x20, 0xff };
70 const GLubyte color1
[4] = { 0x10, 0x20, 0x40, 0xff };
72 GLubyte img
[WIDTH
*HEIGHT
*3];
74 for (i
= 0; i
< HEIGHT
; i
++) {
75 for (j
= 0; j
< WIDTH
; j
++) {
76 int k
= (i
* WIDTH
+ j
) * 3;
79 img
[k
+ 0] = color0
[0];
80 img
[k
+ 1] = color0
[1];
81 img
[k
+ 2] = color0
[2];
84 img
[k
+ 0] = color1
[0];
85 img
[k
+ 1] = color1
[1];
86 img
[k
+ 2] = color1
[2];
91 glTexParameteri(GL_TEXTURE_2D
, GL_GENERATE_MIPMAP_SGIS
, GL_TRUE
);
92 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGB
, WIDTH
, HEIGHT
, 0,
93 GL_RGB
, GL_UNSIGNED_BYTE
, img
);
94 glTexParameteri(GL_TEXTURE_2D
, GL_GENERATE_MIPMAP_SGIS
, GL_FALSE
);
99 static void myinit(void)
103 glShadeModel(GL_FLAT
);
105 glTranslatef(0.0, 0.0, -3.6);
107 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
108 glGenTextures(1, &texImage
);
109 glBindTexture(GL_TEXTURE_2D
, texImage
);
112 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
113 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
114 glTexEnvf(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_DECAL
);
115 glEnable(GL_TEXTURE_2D
);
117 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_BASE_LEVEL
, 0);
118 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAX_LEVEL
, 1);
120 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_LOD
, -1);
121 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAX_LOD
, 1);
123 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
124 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
,
125 GL_NEAREST_MIPMAP_NEAREST
);
130 static void display(void)
133 glBindTexture(GL_TEXTURE_2D
, texImage
);
135 printf("Bias=%.2g\n", LodBias
);
138 glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT
, GL_TEXTURE_LOD_BIAS_EXT
, LodBias
);
140 glClear(GL_COLOR_BUFFER_BIT
);
142 glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0);
143 glTexCoord2f(0.0, tcm
); glVertex3f(-2.0, 1.0, 0.0);
144 glTexCoord2f(tcm
* 3000.0, tcm
); glVertex3f(3000.0, 1.0, -6000.0);
145 glTexCoord2f(tcm
* 3000.0, 0.0); glVertex3f(3000.0, -1.0, -6000.0);
150 static void myReshape(int w
, int h
)
152 glViewport(0, 0, w
, h
);
153 glMatrixMode(GL_PROJECTION
);
155 gluPerspective(60.0, 1.0*(GLfloat
)w
/(GLfloat
)h
, 1.0, 30000.0);
156 glMatrixMode(GL_MODELVIEW
);
161 key(unsigned char k
, int x
, int y
)
175 case 27: /* Escape */
185 static void usage(void)
188 printf(" l/L decrease/increase GL_TEXTURE_LOD_BIAS\n");
189 printf(" SPACE reset values\n");
193 int main(int argc
, char** argv
)
195 glutInit(&argc
, argv
);
196 glutInitDisplayMode (GLUT_SINGLE
| GLUT_RGB
);
197 glutInitWindowSize (600, 600);
198 glutCreateWindow (argv
[0]);
201 glutReshapeFunc (myReshape
);
202 glutDisplayFunc(display
);
203 glutKeyboardFunc(key
);
206 return 0; /* ANSI C requires main to return int. */