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.
54 #include "glut_wrap.h"
59 static GLubyte image1
[imageSize
][imageSize
][4];
60 static GLubyte image2
[imageSize
][imageSize
][4];
61 static GLubyte image3
[imageSize
][imageSize
][4];
62 static GLubyte image4
[imageSize
][imageSize
][4];
63 static GLubyte image5
[imageSize
][imageSize
][4];
64 static GLubyte image6
[imageSize
][imageSize
][4];
66 static GLdouble ztrans
= 0.0;
68 static void makeImages(void)
72 for (i
= 0; i
< imageSize
; i
++) {
73 for (j
= 0; j
< imageSize
; j
++) {
74 c
= ( ((i
& 0x1) == 0) ^ ((j
& 0x1) == 0) ) * 255;
75 image1
[i
][j
][0] = (GLubyte
) c
;
76 image1
[i
][j
][1] = (GLubyte
) c
;
77 image1
[i
][j
][2] = (GLubyte
) c
;
78 image1
[i
][j
][3] = (GLubyte
) 255;
80 image2
[i
][j
][0] = (GLubyte
) c
;
81 image2
[i
][j
][1] = (GLubyte
) c
;
82 image2
[i
][j
][2] = (GLubyte
) 0;
83 image2
[i
][j
][3] = (GLubyte
) 255;
85 image3
[i
][j
][0] = (GLubyte
) c
;
86 image3
[i
][j
][1] = (GLubyte
) 0;
87 image3
[i
][j
][2] = (GLubyte
) c
;
88 image3
[i
][j
][3] = (GLubyte
) 255;
90 image4
[i
][j
][0] = (GLubyte
) 0;
91 image4
[i
][j
][1] = (GLubyte
) c
;
92 image4
[i
][j
][2] = (GLubyte
) c
;
93 image4
[i
][j
][3] = (GLubyte
) 255;
95 image5
[i
][j
][0] = (GLubyte
) 255;
96 image5
[i
][j
][1] = (GLubyte
) c
;
97 image5
[i
][j
][2] = (GLubyte
) c
;
98 image5
[i
][j
][3] = (GLubyte
) 255;
100 image6
[i
][j
][0] = (GLubyte
) c
;
101 image6
[i
][j
][1] = (GLubyte
) c
;
102 image6
[i
][j
][2] = (GLubyte
) 255;
103 image6
[i
][j
][3] = (GLubyte
) 255;
108 static void init(void)
110 GLfloat diffuse
[4] = {1.0, 1.0, 1.0, 1.0};
112 glClearColor (0.0, 0.0, 0.0, 0.0);
113 glEnable(GL_DEPTH_TEST
);
114 glShadeModel(GL_SMOOTH
);
117 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
118 glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
119 glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
120 glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT
, GL_TEXTURE_WRAP_R
, GL_REPEAT
);
121 glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
122 glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
123 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT
, 0, GL_RGBA
, imageSize
,
124 imageSize
, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, image1
);
125 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X_EXT
, 0, GL_RGBA
, imageSize
,
126 imageSize
, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, image4
);
127 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y_EXT
, 0, GL_RGBA
, imageSize
,
128 imageSize
, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, image2
);
129 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT
, 0, GL_RGBA
, imageSize
,
130 imageSize
, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, image5
);
131 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z_EXT
, 0, GL_RGBA
, imageSize
,
132 imageSize
, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, image3
);
133 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT
, 0, GL_RGBA
, imageSize
,
134 imageSize
, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, image6
);
135 glTexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, GL_NORMAL_MAP_EXT
);
136 glTexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, GL_NORMAL_MAP_EXT
);
137 glTexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, GL_NORMAL_MAP_EXT
);
138 glEnable(GL_TEXTURE_GEN_S
);
139 glEnable(GL_TEXTURE_GEN_T
);
140 glEnable(GL_TEXTURE_GEN_R
);
142 glTexEnvf(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_MODULATE
);
144 glEnable(GL_TEXTURE_CUBE_MAP_EXT
);
145 glEnable(GL_LIGHTING
);
147 glEnable(GL_AUTO_NORMAL
);
148 glEnable(GL_NORMALIZE
);
149 glMaterialfv (GL_FRONT
, GL_DIFFUSE
, diffuse
);
152 static void display(void)
154 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
157 glTranslatef (0.0, 0.0, ztrans
);
158 glutSolidSphere (5.0, 20, 10);
163 static void reshape(int w
, int h
)
165 glViewport(0, 0, (GLsizei
) w
, (GLsizei
) h
);
166 glMatrixMode(GL_PROJECTION
);
168 gluPerspective(40.0, (GLfloat
) w
/(GLfloat
) h
, 1.0, 300.0);
169 glMatrixMode(GL_MODELVIEW
);
171 glTranslatef(0.0, 0.0, -20.0);
174 static void keyboard (unsigned char key
, int x
, int y
)
178 ztrans
= ztrans
- 0.2;
182 ztrans
= ztrans
+ 0.2;
193 int main(int argc
, char** argv
)
195 glutInit(&argc
, argv
);
196 glutInitDisplayMode (GLUT_DOUBLE
| GLUT_RGB
| GLUT_DEPTH
);
197 glutInitWindowSize(400, 400);
198 glutInitWindowPosition(100, 100);
199 glutCreateWindow (argv
[0]);
201 glutDisplayFunc(display
);
202 glutReshapeFunc(reshape
);
203 glutKeyboardFunc(keyboard
);