2 * Copyright (c) 1993-1997, Silicon Graphics, Inc.
4 * Permission to use, copy, modify, and distribute this software for
5 * any purpose and without fee is hereby granted, provided that the above
6 * copyright notice appear in all copies and that both the copyright notice
7 * and this permission notice appear in supporting documentation, and that
8 * the name of Silicon Graphics, Inc. not be used in advertising
9 * or publicity pertaining to distribution of the software without specific,
10 * written prior permission.
12 * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
13 * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
14 * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
15 * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
16 * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
17 * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
18 * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
19 * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
20 * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
21 * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
22 * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
23 * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
25 * US Government Users Restricted Rights
26 * Use, duplication, or disclosure by the Government is subject to
27 * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
28 * (c)(1)(ii) of the Rights in Technical Data and Computer Software
29 * clause at DFARS 252.227-7013 and/or in similar or successor
30 * clauses in the FAR or the DOD or NASA FAR Supplement.
31 * Unpublished-- rights reserved under the copyright laws of the
32 * United States. Contractor/manufacturer is Silicon Graphics,
33 * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
35 * OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
39 * This program draws a texture mapped teapot with
40 * automatically generated texture coordinates. The
41 * texture is rendered as stripes on the teapot.
42 * Initially, the object is drawn with texture coordinates
43 * based upon the object coordinates of the vertex
44 * and distance from the plane x = 0. Pressing the 'e'
45 * key changes the coordinate generation to eye coordinates
46 * of the vertex. Pressing the 'o' key switches it back
47 * to the object coordinates. Pressing the 's' key
48 * changes the plane to a slanted one (x + y + z = 0).
49 * Pressing the 'x' key switches it back to x = 0.
52 #include "glut_wrap.h"
56 #define stripeImageWidth 32
57 GLubyte stripeImage
[4*stripeImageWidth
];
60 static GLuint texName
;
63 static void makeStripeImage(void)
67 for (j
= 0; j
< stripeImageWidth
; j
++) {
68 stripeImage
[4*j
] = (GLubyte
) ((j
<=4) ? 255 : 0);
69 stripeImage
[4*j
+1] = (GLubyte
) ((j
>4) ? 255 : 0);
70 stripeImage
[4*j
+2] = (GLubyte
) 0;
71 stripeImage
[4*j
+3] = (GLubyte
) 255;
75 /* planes for texture coordinate generation */
76 static GLfloat xequalzero
[] = {1.0, 0.0, 0.0, 0.0};
77 static GLfloat slanted
[] = {1.0, 1.0, 1.0, 0.0};
78 static GLfloat
*currentCoeff
;
79 static GLenum currentPlane
;
80 static GLint currentGenMode
;
82 static void init(void)
84 glClearColor (0.0, 0.0, 0.0, 0.0);
85 glEnable(GL_DEPTH_TEST
);
86 glShadeModel(GL_SMOOTH
);
89 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
92 glGenTextures(1, &texName
);
93 glBindTexture(GL_TEXTURE_1D
, texName
);
95 glTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
96 glTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
97 glTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
99 glTexImage1D(GL_TEXTURE_1D
, 0, GL_RGBA
, stripeImageWidth
, 0,
100 GL_RGBA
, GL_UNSIGNED_BYTE
, stripeImage
);
102 glTexImage1D(GL_TEXTURE_1D
, 0, 4, stripeImageWidth
, 0,
103 GL_RGBA
, GL_UNSIGNED_BYTE
, stripeImage
);
106 glTexEnvf(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_MODULATE
);
107 currentCoeff
= xequalzero
;
108 currentGenMode
= GL_OBJECT_LINEAR
;
109 currentPlane
= GL_OBJECT_PLANE
;
110 glTexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, currentGenMode
);
111 glTexGenfv(GL_S
, currentPlane
, currentCoeff
);
113 glEnable(GL_TEXTURE_GEN_S
);
114 glEnable(GL_TEXTURE_1D
);
115 glEnable(GL_CULL_FACE
);
116 glEnable(GL_LIGHTING
);
118 glEnable(GL_AUTO_NORMAL
);
119 glEnable(GL_NORMALIZE
);
122 glMaterialf (GL_FRONT
, GL_SHININESS
, 64.0);
125 static void display(void)
127 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
130 glRotatef(45.0, 0.0, 0.0, 1.0);
131 #ifdef GL_VERSION_1_1
132 glBindTexture(GL_TEXTURE_1D
, texName
);
134 glutSolidTeapot(2.0);
139 static void reshape(int w
, int h
)
141 glViewport(0, 0, (GLsizei
) w
, (GLsizei
) h
);
142 glMatrixMode(GL_PROJECTION
);
145 glOrtho (-3.5, 3.5, -3.5*(GLfloat
)h
/(GLfloat
)w
,
146 3.5*(GLfloat
)h
/(GLfloat
)w
, -3.5, 3.5);
148 glOrtho (-3.5*(GLfloat
)w
/(GLfloat
)h
,
149 3.5*(GLfloat
)w
/(GLfloat
)h
, -3.5, 3.5, -3.5, 3.5);
150 glMatrixMode(GL_MODELVIEW
);
155 static void keyboard (unsigned char key
, int x
, int y
)
160 currentGenMode
= GL_EYE_LINEAR
;
161 currentPlane
= GL_EYE_PLANE
;
162 glTexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, currentGenMode
);
163 glTexGenfv(GL_S
, currentPlane
, currentCoeff
);
168 currentGenMode
= GL_OBJECT_LINEAR
;
169 currentPlane
= GL_OBJECT_PLANE
;
170 glTexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, currentGenMode
);
171 glTexGenfv(GL_S
, currentPlane
, currentCoeff
);
176 currentCoeff
= slanted
;
177 glTexGenfv(GL_S
, currentPlane
, currentCoeff
);
182 currentCoeff
= xequalzero
;
183 glTexGenfv(GL_S
, currentPlane
, currentCoeff
);
194 int main(int argc
, char** argv
)
196 glutInit(&argc
, argv
);
197 glutInitDisplayMode (GLUT_SINGLE
| GLUT_RGB
| GLUT_DEPTH
);
198 glutInitWindowSize(256, 256);
199 glutInitWindowPosition(100, 100);
200 glutCreateWindow (argv
[0]);
202 glutDisplayFunc(display
);
203 glutReshapeFunc(reshape
);
204 glutKeyboardFunc(keyboard
);