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.
52 static GLfloat LodBias
= 6.0; /* make smallest miplevel visible */
53 static GLuint texImage
;
61 LodBias
= 6.0; /* make smallest miplevel visible */
65 static void MakeImage(void)
67 const GLubyte color0
[4] = { 0xff, 0x80, 0x20, 0xff };
68 const GLubyte color1
[4] = { 0x10, 0x20, 0x40, 0xff };
70 GLubyte img
[WIDTH
*HEIGHT
*3];
72 for (i
= 0; i
< HEIGHT
; i
++) {
73 for (j
= 0; j
< WIDTH
; j
++) {
74 int k
= (i
* WIDTH
+ j
) * 3;
77 img
[k
+ 0] = color0
[0];
78 img
[k
+ 1] = color0
[1];
79 img
[k
+ 2] = color0
[2];
82 img
[k
+ 0] = color1
[0];
83 img
[k
+ 1] = color1
[1];
84 img
[k
+ 2] = color1
[2];
89 glTexParameteri(GL_TEXTURE_2D
, GL_GENERATE_MIPMAP_SGIS
, GL_TRUE
);
90 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGB
, WIDTH
, HEIGHT
, 0,
91 GL_RGB
, GL_UNSIGNED_BYTE
, img
);
92 glTexParameteri(GL_TEXTURE_2D
, GL_GENERATE_MIPMAP_SGIS
, GL_FALSE
);
97 static void myinit(void)
101 glShadeModel(GL_FLAT
);
103 glTranslatef(0.0, 0.0, -3.6);
105 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
106 glGenTextures(1, &texImage
);
107 glBindTexture(GL_TEXTURE_2D
, texImage
);
110 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
111 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
112 glTexEnvf(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_DECAL
);
113 glEnable(GL_TEXTURE_2D
);
115 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_BASE_LEVEL
, 0);
116 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAX_LEVEL
, 1);
118 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_LOD
, -1);
119 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAX_LOD
, 1);
121 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
122 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
,
123 GL_NEAREST_MIPMAP_NEAREST
);
128 static void display(void)
131 glBindTexture(GL_TEXTURE_2D
, texImage
);
133 printf("Bias=%.2g\n", LodBias
);
136 glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT
, GL_TEXTURE_LOD_BIAS_EXT
, LodBias
);
138 glClear(GL_COLOR_BUFFER_BIT
);
140 glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0);
141 glTexCoord2f(0.0, tcm
); glVertex3f(-2.0, 1.0, 0.0);
142 glTexCoord2f(tcm
* 3000.0, tcm
); glVertex3f(3000.0, 1.0, -6000.0);
143 glTexCoord2f(tcm
* 3000.0, 0.0); glVertex3f(3000.0, -1.0, -6000.0);
148 static void myReshape(int w
, int h
)
150 glViewport(0, 0, w
, h
);
151 glMatrixMode(GL_PROJECTION
);
153 gluPerspective(60.0, 1.0*(GLfloat
)w
/(GLfloat
)h
, 1.0, 30000.0);
154 glMatrixMode(GL_MODELVIEW
);
159 key(unsigned char k
, int x
, int y
)
173 case 27: /* Escape */
183 static void usage(void)
186 printf(" l/L decrease/increase GL_TEXTURE_LOD_BIAS\n");
187 printf(" SPACE reset values\n");
191 int main(int argc
, char** argv
)
193 glutInit(&argc
, argv
);
194 glutInitDisplayMode (GLUT_SINGLE
| GLUT_RGB
);
195 glutInitWindowSize (600, 600);
196 glutCreateWindow (argv
[0]);
199 glutReshapeFunc (myReshape
);
200 glutDisplayFunc(display
);
201 glutKeyboardFunc(key
);
204 return 0; /* ANSI C requires main to return int. */