2 * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc.
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that (i) the above copyright notices and this permission notice appear in
7 * all copies of the software and related documentation, and (ii) the name of
8 * Silicon Graphics may not be used in any advertising or
9 * publicity relating to the software without the specific, prior written
10 * permission of Silicon Graphics.
12 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF
14 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
17 * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR
18 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
21 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
36 #define PI 3.141592654
40 #define RD 0xA4,0x00,0x00,0xFF
41 #define WT 0xFF,0xFF,0xFF,0xFF
42 #define brickImageWidth 16
43 #define brickImageHeight 16
48 GLenum rgb
, doubleBuffer
;
65 GLenum doDither
= GL_TRUE
;
66 GLenum shade
= GL_TRUE
;
67 GLenum texture
= GL_TRUE
;
69 float xRotation
= 30.0, yRotation
= 30.0, zRotation
= 0.0;
70 GLint radius1
, radius2
;
71 GLdouble angle1
, angle2
;
74 GLint orientation
= GLU_OUTSIDE
;
76 GLUquadricObj
*quadObj
;
78 GLubyte brickImage
[4*brickImageWidth
*brickImageHeight
] = {
79 RD
, RD
, RD
, RD
, RD
, RD
, RD
, RD
, RD
, WT
, RD
, RD
, RD
, RD
, RD
, RD
,
80 RD
, RD
, RD
, RD
, RD
, RD
, RD
, RD
, RD
, WT
, RD
, RD
, RD
, RD
, RD
, RD
,
81 RD
, RD
, RD
, RD
, RD
, RD
, RD
, RD
, RD
, WT
, RD
, RD
, RD
, RD
, RD
, RD
,
82 RD
, RD
, RD
, RD
, RD
, RD
, RD
, RD
, RD
, WT
, RD
, RD
, RD
, RD
, RD
, RD
,
83 WT
, WT
, WT
, WT
, WT
, WT
, WT
, WT
, WT
, WT
, WT
, WT
, WT
, WT
, WT
, WT
,
84 RD
, RD
, RD
, WT
, RD
, RD
, RD
, RD
, RD
, RD
, RD
, RD
, RD
, WT
, RD
, RD
,
85 RD
, RD
, RD
, WT
, RD
, RD
, RD
, RD
, RD
, RD
, RD
, RD
, RD
, WT
, RD
, RD
,
86 RD
, RD
, RD
, WT
, RD
, RD
, RD
, RD
, RD
, RD
, RD
, RD
, RD
, WT
, RD
, RD
,
87 RD
, RD
, RD
, WT
, RD
, RD
, RD
, RD
, RD
, RD
, RD
, RD
, RD
, WT
, RD
, RD
,
88 WT
, WT
, WT
, WT
, WT
, WT
, WT
, WT
, WT
, WT
, WT
, WT
, WT
, WT
, WT
, WT
,
89 RD
, RD
, RD
, RD
, RD
, RD
, RD
, WT
, RD
, RD
, RD
, RD
, RD
, RD
, RD
, RD
,
90 RD
, RD
, RD
, RD
, RD
, RD
, RD
, WT
, RD
, RD
, RD
, RD
, RD
, RD
, RD
, RD
,
91 RD
, RD
, RD
, RD
, RD
, RD
, RD
, WT
, RD
, RD
, RD
, RD
, RD
, RD
, RD
, RD
,
92 RD
, RD
, RD
, RD
, RD
, RD
, RD
, WT
, RD
, RD
, RD
, RD
, RD
, RD
, RD
, RD
,
93 WT
, WT
, WT
, WT
, WT
, WT
, WT
, WT
, WT
, WT
, WT
, WT
, WT
, WT
, WT
, WT
,
94 RD
, RD
, RD
, RD
, WT
, RD
, RD
, RD
, RD
, RD
, RD
, RD
, RD
, RD
, WT
, RD
96 char *texFileName
= 0;
99 static void CALLBACK
ErrorHandler(GLenum which
)
102 fprintf(stderr
, "Quad Error: %s\n", gluErrorString(which
));
105 static void Init(void)
107 static GLint colorIndexes
[3] = {0, 200, 255};
108 static float ambient
[] = {0.1, 0.1, 0.1, 1.0};
109 static float diffuse
[] = {0.5, 1.0, 1.0, 1.0};
110 static float position
[] = {90.0, 90.0, 150.0, 0.0};
111 static float front_mat_shininess
[] = {30.0};
112 static float front_mat_specular
[] = {0.2, 0.2, 0.2, 1.0};
113 static float front_mat_diffuse
[] = {0.5, 0.28, 0.38, 1.0};
114 static float back_mat_shininess
[] = {50.0};
115 static float back_mat_specular
[] = {0.5, 0.5, 0.2, 1.0};
116 static float back_mat_diffuse
[] = {1.0, 1.0, 0.2, 1.0};
117 static float lmodel_ambient
[] = {1.0, 1.0, 1.0, 1.0};
118 static float lmodel_twoside
[] = {GL_TRUE
};
119 static float decal
[] = {GL_DECAL
};
120 static float repeat
[] = {GL_REPEAT
};
121 static float nearest
[] = {GL_NEAREST
};
122 static PPMImage
*image
;
127 glClearColor(0.0, 0.0, 0.0, 0.0);
129 glEnable(GL_DEPTH_TEST
);
131 glLightfv(GL_LIGHT0
, GL_AMBIENT
, ambient
);
132 glLightfv(GL_LIGHT0
, GL_DIFFUSE
, diffuse
);
133 glLightfv(GL_LIGHT0
, GL_POSITION
, position
);
134 glLightModelfv(GL_LIGHT_MODEL_AMBIENT
, lmodel_ambient
);
135 glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE
, lmodel_twoside
);
136 glEnable(GL_LIGHTING
);
139 glMaterialfv(GL_FRONT
, GL_SHININESS
, front_mat_shininess
);
140 glMaterialfv(GL_FRONT
, GL_SPECULAR
, front_mat_specular
);
141 glMaterialfv(GL_FRONT
, GL_DIFFUSE
, front_mat_diffuse
);
142 glMaterialfv(GL_BACK
, GL_SHININESS
, back_mat_shininess
);
143 glMaterialfv(GL_BACK
, GL_SPECULAR
, back_mat_specular
);
144 glMaterialfv(GL_BACK
, GL_DIFFUSE
, back_mat_diffuse
);
146 glMaterialiv( GL_FRONT_AND_BACK
, GL_COLOR_INDEXES
, colorIndexes
);
149 glTexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, decal
);
150 glTexParameterfv(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, repeat
);
151 glTexParameterfv(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, repeat
);
152 glTexParameterfv(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, nearest
);
153 glTexParameterfv(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, nearest
);
155 image
= LoadPPM(texFileName
);
156 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
157 gluBuild2DMipmaps(GL_TEXTURE_2D
, 3, image
->sizeX
, image
->sizeY
,
158 GL_RGB
, GL_UNSIGNED_BYTE
, image
->data
);
160 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
161 glTexImage2D(GL_TEXTURE_2D
, 0, 4, brickImageWidth
, brickImageHeight
,
162 0, GL_RGBA
, GL_UNSIGNED_BYTE
, (GLvoid
*)brickImage
);
165 quadObj
= gluNewQuadric();
166 gluQuadricCallback(quadObj
, GLU_ERROR
, ErrorHandler
);
177 static void Reshape(int width
, int height
)
180 glViewport(0, 0, (GLint
)width
, (GLint
)height
);
182 glMatrixMode(GL_PROJECTION
);
184 glFrustum(-1, 1, -1, 1, 1, 10);
185 gluLookAt(2, 2, 2, 0, 0, 0, 0, 0, 1);
186 glMatrixMode(GL_MODELVIEW
);
189 static void Key2(int key
, int x
, int y
)
212 static void Key(unsigned char key
, int x
, int y
)
227 gluQuadricDrawStyle(quadObj
, GLU_FILL
);
230 gluQuadricDrawStyle(quadObj
, GLU_POINT
);
233 gluQuadricDrawStyle(quadObj
, GLU_LINE
);
236 gluQuadricDrawStyle(quadObj
, GLU_SILHOUETTE
);
242 glShadeModel(GL_SMOOTH
);
243 gluQuadricNormals(quadObj
, GLU_SMOOTH
);
245 glShadeModel(GL_FLAT
);
246 gluQuadricNormals(quadObj
, GLU_FLAT
);
265 switch(orientation
) {
267 orientation
= GLU_INSIDE
;
271 orientation
= GLU_OUTSIDE
;
274 gluQuadricOrientation(quadObj
, orientation
);
278 whichQuadric
= (whichQuadric
+ 1) % 4;
319 gluQuadricTexture(quadObj
, GL_TRUE
);
320 glEnable(GL_TEXTURE_2D
);
322 gluQuadricTexture(quadObj
, GL_FALSE
);
323 glDisable(GL_TEXTURE_2D
);
328 glDisable(GL_CULL_FACE
);
331 glEnable(GL_CULL_FACE
);
332 glCullFace(GL_FRONT
);
335 glEnable(GL_CULL_FACE
);
347 doDither
= !doDither
;
348 (doDither
) ? glEnable(GL_DITHER
) : glDisable(GL_DITHER
);
357 static void Draw(void)
361 glRotatef(xRotation
, 1, 0, 0);
362 glRotatef(yRotation
, 0, 1, 0);
363 glRotatef(zRotation
, 0, 0, 1);
365 glClear(GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
367 glColor3f(1.0, 1.0, 1.0);
368 switch (whichQuadric
) {
370 glTranslatef(0, 0, -height
/20.0);
371 gluCylinder(quadObj
, radius1
/10.0, radius2
/10.0, height
/10.0,
375 gluSphere(quadObj
, radius1
/10.0, slices
, stacks
);
378 gluPartialDisk(quadObj
, radius2
/10.0, radius1
/10.0, slices
,
379 stacks
, angle1
, angle2
);
382 gluDisk(quadObj
, radius2
/10.0, radius1
/10.0, slices
, stacks
);
393 static GLenum
Args(int argc
, char **argv
)
398 doubleBuffer
= GL_FALSE
;
400 for (i
= 1; i
< argc
; i
++) {
401 if (strcmp(argv
[i
], "-ci") == 0) {
403 } else if (strcmp(argv
[i
], "-rgb") == 0) {
405 } else if (strcmp(argv
[i
], "-sb") == 0) {
406 doubleBuffer
= GL_FALSE
;
407 } else if (strcmp(argv
[i
], "-db") == 0) {
408 doubleBuffer
= GL_TRUE
;
409 } else if (strcmp(argv
[i
], "-f") == 0) {
410 if (i
+1 >= argc
|| argv
[i
+1][0] == '-') {
411 printf("-f (No file name).\n");
414 texFileName
= argv
[++i
];
417 printf("%s (Bad option).\n", argv
[i
]);
424 int main(int argc
, char **argv
)
428 glutInit(&argc
, argv
);
430 if (Args(argc
, argv
) == GL_FALSE
) {
434 glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300);
437 type
|= (rgb
) ? GLUT_RGB
: GLUT_INDEX
;
438 type
|= (doubleBuffer
) ? GLUT_DOUBLE
: GLUT_SINGLE
;
439 glutInitDisplayMode(type
);
441 if (glutCreateWindow("Quad Test") == GL_FALSE
) {
449 glutReshapeFunc(Reshape
);
450 glutKeyboardFunc(Key
);
451 glutSpecialFunc(Key2
);
452 glutDisplayFunc(Draw
);