2 * Copyright (c) 1993-2003, Silicon Graphics, Inc.
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose and without fee is hereby granted, provided that the above
7 * copyright notice appear in all copies and that both the copyright
8 * notice and this permission notice appear in supporting documentation,
9 * and that the name of Silicon Graphics, Inc. not be used in
10 * advertising or publicity pertaining to distribution of the software
11 * without specific, written prior permission.
13 * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" AND
14 * 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 KIND,
19 * OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, LOSS OF
20 * PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF THIRD
21 * PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN ADVISED OF
22 * THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON ANY THEORY OF
23 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE POSSESSION, USE
24 * 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 clauses
31 * in the FAR or the DOD or NASA FAR Supplement. Unpublished - rights
32 * reserved under the copyright laws of the United States.
34 * Contractor/manufacturer is:
35 * Silicon Graphics, Inc.
36 * 1500 Crittenden Lane
37 * Mountain View, CA 94043
38 * United State of America
40 * OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
45 * This program demonstrates cube map textures.
46 * Six different colored checker board textures are
47 * created and applied to a lit sphere.
49 * Pressing the 'f' and 'b' keys translate the viewer
50 * forward and backward.
58 static GLubyte image1
[imageSize
][imageSize
][4];
59 static GLubyte image2
[imageSize
][imageSize
][4];
60 static GLubyte image3
[imageSize
][imageSize
][4];
61 static GLubyte image4
[imageSize
][imageSize
][4];
62 static GLubyte image5
[imageSize
][imageSize
][4];
63 static GLubyte image6
[imageSize
][imageSize
][4];
65 static GLdouble ztrans
= 0.0;
67 static void makeImages(void)
71 for (i
= 0; i
< imageSize
; i
++) {
72 for (j
= 0; j
< imageSize
; j
++) {
73 c
= ( ((i
& 0x1) == 0) ^ ((j
& 0x1) == 0) ) * 255;
74 image1
[i
][j
][0] = (GLubyte
) c
;
75 image1
[i
][j
][1] = (GLubyte
) c
;
76 image1
[i
][j
][2] = (GLubyte
) c
;
77 image1
[i
][j
][3] = (GLubyte
) 255;
79 image2
[i
][j
][0] = (GLubyte
) c
;
80 image2
[i
][j
][1] = (GLubyte
) c
;
81 image2
[i
][j
][2] = (GLubyte
) 0;
82 image2
[i
][j
][3] = (GLubyte
) 255;
84 image3
[i
][j
][0] = (GLubyte
) c
;
85 image3
[i
][j
][1] = (GLubyte
) 0;
86 image3
[i
][j
][2] = (GLubyte
) c
;
87 image3
[i
][j
][3] = (GLubyte
) 255;
89 image4
[i
][j
][0] = (GLubyte
) 0;
90 image4
[i
][j
][1] = (GLubyte
) c
;
91 image4
[i
][j
][2] = (GLubyte
) c
;
92 image4
[i
][j
][3] = (GLubyte
) 255;
94 image5
[i
][j
][0] = (GLubyte
) 255;
95 image5
[i
][j
][1] = (GLubyte
) c
;
96 image5
[i
][j
][2] = (GLubyte
) c
;
97 image5
[i
][j
][3] = (GLubyte
) 255;
99 image6
[i
][j
][0] = (GLubyte
) c
;
100 image6
[i
][j
][1] = (GLubyte
) c
;
101 image6
[i
][j
][2] = (GLubyte
) 255;
102 image6
[i
][j
][3] = (GLubyte
) 255;
107 static void init(void)
109 GLfloat diffuse
[4] = {1.0, 1.0, 1.0, 1.0};
111 glClearColor (0.0, 0.0, 0.0, 0.0);
112 glEnable(GL_DEPTH_TEST
);
113 glShadeModel(GL_SMOOTH
);
116 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
117 glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
118 glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
119 glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT
, GL_TEXTURE_WRAP_R
, GL_REPEAT
);
120 glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
121 glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
122 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT
, 0, GL_RGBA
, imageSize
,
123 imageSize
, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, image1
);
124 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X_EXT
, 0, GL_RGBA
, imageSize
,
125 imageSize
, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, image4
);
126 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y_EXT
, 0, GL_RGBA
, imageSize
,
127 imageSize
, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, image2
);
128 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT
, 0, GL_RGBA
, imageSize
,
129 imageSize
, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, image5
);
130 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z_EXT
, 0, GL_RGBA
, imageSize
,
131 imageSize
, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, image3
);
132 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT
, 0, GL_RGBA
, imageSize
,
133 imageSize
, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, image6
);
134 glTexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, GL_NORMAL_MAP_EXT
);
135 glTexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, GL_NORMAL_MAP_EXT
);
136 glTexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, GL_NORMAL_MAP_EXT
);
137 glEnable(GL_TEXTURE_GEN_S
);
138 glEnable(GL_TEXTURE_GEN_T
);
139 glEnable(GL_TEXTURE_GEN_R
);
141 glTexEnvf(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_MODULATE
);
143 glEnable(GL_TEXTURE_CUBE_MAP_EXT
);
144 glEnable(GL_LIGHTING
);
146 glEnable(GL_AUTO_NORMAL
);
147 glEnable(GL_NORMALIZE
);
148 glMaterialfv (GL_FRONT
, GL_DIFFUSE
, diffuse
);
151 static void display(void)
153 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
156 glTranslatef (0.0, 0.0, ztrans
);
157 glutSolidSphere (5.0, 20, 10);
162 static void reshape(int w
, int h
)
164 glViewport(0, 0, (GLsizei
) w
, (GLsizei
) h
);
165 glMatrixMode(GL_PROJECTION
);
167 gluPerspective(40.0, (GLfloat
) w
/(GLfloat
) h
, 1.0, 300.0);
168 glMatrixMode(GL_MODELVIEW
);
170 glTranslatef(0.0, 0.0, -20.0);
173 static void keyboard (unsigned char key
, int x
, int y
)
177 ztrans
= ztrans
- 0.2;
181 ztrans
= ztrans
+ 0.2;
192 int main(int argc
, char** argv
)
194 glutInit(&argc
, argv
);
195 glutInitDisplayMode (GLUT_DOUBLE
| GLUT_RGB
| GLUT_DEPTH
);
196 glutInitWindowSize(400, 400);
197 glutInitWindowPosition(100, 100);
198 glutCreateWindow (argv
[0]);
200 glutDisplayFunc(display
);
201 glutReshapeFunc(reshape
);
202 glutKeyboardFunc(keyboard
);