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
31 #define OPENGL_WIDTH 24
32 #define OPENGL_HEIGHT 13
35 GLenum rgb
, doubleBuffer
, windType
;
36 GLint objectIndex
= 0;
38 float angleX
= 0.0, angleY
= 0.0, angleZ
= 0.0;
39 float scaleX
= 1.0, scaleY
= 1.0, scaleZ
= 1.0;
40 float shiftX
= 0.0, shiftY
= 0.0, shiftZ
= 0.0;
45 static void Init(void)
48 bases
[0] = glGenLists(1);
49 glNewList(bases
[0], GL_COMPILE
);
50 glutWireSphere(1.0, 20, 10);
53 bases
[1] = glGenLists(1);
54 glNewList(bases
[1], GL_COMPILE
);
55 glutSolidSphere(1.0, 20, 10);
58 bases
[2] = glGenLists(1);
59 glNewList(bases
[2], GL_COMPILE
);
63 bases
[3] = glGenLists(1);
64 glNewList(bases
[3], GL_COMPILE
);
68 bases
[4] = glGenLists(1);
69 glNewList(bases
[4], GL_COMPILE
);
70 glutWireTorus(1.0, 1.0, 10, 20);
73 bases
[5] = glGenLists(1);
74 glNewList(bases
[5], GL_COMPILE
);
75 glutSolidTorus(1.0, 1.0, 10, 20);
78 bases
[6] = glGenLists(1);
79 glNewList(bases
[6], GL_COMPILE
);
80 glutWireIcosahedron();
83 bases
[7] = glGenLists(1);
84 glNewList(bases
[7], GL_COMPILE
);
85 glutSolidIcosahedron();
88 bases
[8] = glGenLists(1);
89 glNewList(bases
[8], GL_COMPILE
);
93 bases
[9] = glGenLists(1);
94 glNewList(bases
[9], GL_COMPILE
);
95 glutSolidOctahedron();
98 bases
[10] = glGenLists(1);
99 glNewList(bases
[10], GL_COMPILE
);
100 glutWireTetrahedron();
103 bases
[11] = glGenLists(1);
104 glNewList(bases
[11], GL_COMPILE
);
105 glutSolidTetrahedron();
108 bases
[12] = glGenLists(1);
109 glNewList(bases
[12], GL_COMPILE
);
110 glutWireDodecahedron();
113 bases
[13] = glGenLists(1);
114 glNewList(bases
[13], GL_COMPILE
);
115 glutSolidDodecahedron();
118 bases
[14] = glGenLists(1);
119 glNewList(bases
[14], GL_COMPILE
);
120 glutWireCone(5.0, 5.0, 20, 10);
123 bases
[15] = glGenLists(1);
124 glNewList(bases
[15], GL_COMPILE
);
125 glutSolidCone(5.0, 5.0, 20, 10);
128 bases
[16] = glGenLists(1);
129 glNewList(bases
[16], GL_COMPILE
);
133 bases
[17] = glGenLists(1);
134 glNewList(bases
[17], GL_COMPILE
);
135 glutSolidTeapot(1.0);
138 glClearColor(0.0, 0.0, 0.0, 0.0);
142 static void Reshape(int width
, int height
)
145 glViewport(0, 0, (GLint
)width
, (GLint
)height
);
147 glMatrixMode(GL_PROJECTION
);
149 glOrtho(-400.0, 400.0, -200.0, 200.0, -400.0, 400.0);
150 glMatrixMode(GL_MODELVIEW
);
153 static void Key2(int key
, int x
, int y
)
176 static void Key(unsigned char key
, int x
, int y
)
185 if (objectIndex
> 17) {
228 angleX
= 360.0 + angleX
;
233 if (angleX
> 360.0) {
234 angleX
= angleX
- 360.0;
240 angleY
= 360.0 + angleY
;
245 if (angleY
> 360.0) {
246 angleY
= angleY
- 360.0;
252 angleZ
= 360.0 + angleZ
;
257 if (angleZ
> 360.0) {
258 angleZ
= angleZ
- 360.0;
268 static void Draw(void)
271 glClear(GL_COLOR_BUFFER_BIT
);
273 SetColor(COLOR_WHITE
);
277 glTranslatef(shiftX
, shiftY
, shiftZ
);
278 glRotatef(angleX
, 1.0, 0.0, 0.0);
279 glRotatef(angleY
, 0.0, 1.0, 0.0);
280 glRotatef(angleZ
, 0.0, 0.0, 1.0);
281 glScalef(scaleX
, scaleY
, scaleZ
);
283 glCallList(bases
[objectIndex
]);
293 static GLenum
Args(int argc
, char **argv
)
298 doubleBuffer
= GL_FALSE
;
300 for (i
= 1; i
< argc
; i
++) {
301 if (strcmp(argv
[i
], "-ci") == 0) {
303 } else if (strcmp(argv
[i
], "-rgb") == 0) {
305 } else if (strcmp(argv
[i
], "-sb") == 0) {
306 doubleBuffer
= GL_FALSE
;
307 } else if (strcmp(argv
[i
], "-db") == 0) {
308 doubleBuffer
= GL_TRUE
;
310 printf("%s (Bad option).\n", argv
[i
]);
317 int main(int argc
, char **argv
)
319 glutInit(&argc
, argv
);
321 if (Args(argc
, argv
) == GL_FALSE
) {
325 glutInitWindowPosition(0, 0); glutInitWindowSize( 400, 400);
327 windType
= (rgb
) ? GLUT_RGB
: GLUT_INDEX
;
328 windType
|= (doubleBuffer
) ? GLUT_DOUBLE
: GLUT_SINGLE
;
329 glutInitDisplayMode(windType
);
331 if (glutCreateWindow("Font Test") == GL_FALSE
) {
339 glutReshapeFunc(Reshape
);
340 glutKeyboardFunc(Key
);
341 glutSpecialFunc(Key2
);
342 glutDisplayFunc(Draw
);