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.
44 * This program demonstrates using a three-dimensional texture.
45 * It creates a 3D texture and then renders two rectangles
46 * with different texture coordinates to obtain different
47 * "slices" of the 3D texture.
59 static GLubyte image
[iDepth
][iHeight
][iWidth
][3];
60 static GLuint texName
;
62 /* Create a 16x16x16x3 array with different color values in
63 * each array element [r, g, b]. Values range from 0 to 255.
66 static void makeImage(void)
70 for (s
= 0; s
< 16; s
++)
71 for (t
= 0; t
< 16; t
++)
72 for (r
= 0; r
< 16; r
++) {
73 image
[r
][t
][s
][0] = (GLubyte
) (s
* 17);
74 image
[r
][t
][s
][1] = (GLubyte
) (t
* 17);
75 image
[r
][t
][s
][2] = (GLubyte
) (r
* 17);
79 static void init(void)
81 glClearColor (0.0, 0.0, 0.0, 0.0);
82 glShadeModel(GL_FLAT
);
83 glEnable(GL_DEPTH_TEST
);
86 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
88 glGenTextures(1, &texName
);
89 glBindTexture(GL_TEXTURE_3D
, texName
);
90 glTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_WRAP_S
, GL_CLAMP
);
91 glTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_WRAP_T
, GL_CLAMP
);
92 glTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_WRAP_R
, GL_CLAMP
);
93 glTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_MAG_FILTER
,
95 glTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_MIN_FILTER
,
97 glTexImage3D(GL_TEXTURE_3D
, 0, GL_RGB
, iWidth
, iHeight
,
98 iDepth
, 0, GL_RGB
, GL_UNSIGNED_BYTE
, image
);
99 glEnable(GL_TEXTURE_3D
);
102 static void display(void)
104 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
106 glTexCoord3f(0.0, 0.0, 0.0); glVertex3f(-2.25, -1.0, 0.0);
107 glTexCoord3f(0.0, 1.0, 0.0); glVertex3f(-2.25, 1.0, 0.0);
108 glTexCoord3f(1.0, 1.0, 1.0); glVertex3f(-0.25, 1.0, 0.0);
109 glTexCoord3f(1.0, 0.0, 1.0); glVertex3f(-0.25, -1.0, 0.0);
111 glTexCoord3f(0.0, 0.0, 1.0); glVertex3f(0.25, -1.0, 0.0);
112 glTexCoord3f(0.0, 1.0, 1.0); glVertex3f(0.25, 1.0, 0.0);
113 glTexCoord3f(1.0, 1.0, 0.0); glVertex3f(2.25, 1.0, 0.0);
114 glTexCoord3f(1.0, 0.0, 0.0); glVertex3f(2.25, -1.0, 0.0);
119 static void reshape(int w
, int h
)
121 glViewport(0, 0, (GLsizei
) w
, (GLsizei
) h
);
122 glMatrixMode(GL_PROJECTION
);
124 gluPerspective(60.0, (GLfloat
) w
/(GLfloat
) h
, 1.0, 30.0);
125 glMatrixMode(GL_MODELVIEW
);
127 glTranslatef(0.0, 0.0, -4.0);
130 static void keyboard(unsigned char key
, int x
, int y
)
139 int main(int argc
, char** argv
)
141 glutInit(&argc
, argv
);
142 glutInitDisplayMode(GLUT_SINGLE
| GLUT_RGB
| GLUT_DEPTH
);
143 glutInitWindowSize(250, 250);
144 glutInitWindowPosition(100, 100);
145 glutCreateWindow(argv
[0]);
148 glutReshapeFunc(reshape
);
149 glutDisplayFunc(display
);
150 glutKeyboardFunc (keyboard
);
155 int main(int argc
, char** argv
)
157 fprintf (stderr
, "This program demonstrates a feature which is not in OpenGL Version 1.0 or 1.1.\n");
158 fprintf (stderr
, "If your implementation of OpenGL has the right extensions,\n");
159 fprintf (stderr
, "you may be able to modify this program to make it run.\n");