1/* 2 * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. 3 * 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. 11 * 12 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF 13 * ANY KIND, 14 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 15 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 16 * 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 22 * OF THIS SOFTWARE. 23 */ 24 25#include <stdio.h> 26#include <string.h> 27#include <stdlib.h> 28#include "glut_wrap.h" 29 30 31#define OPENGL_WIDTH 24 32#define OPENGL_HEIGHT 13 33 34 35GLenum rgb, doubleBuffer, windType; 36GLint objectIndex = 0; 37GLuint bases[20]; 38float angleX = 0.0, angleY = 0.0, angleZ = 0.0; 39float scaleX = 1.0, scaleY = 1.0, scaleZ = 1.0; 40float shiftX = 0.0, shiftY = 0.0, shiftZ = 0.0; 41 42 43#include "tkmap.c" 44 45static void Init(void) 46{ 47 48 bases[0] = glGenLists(1); 49 glNewList(bases[0], GL_COMPILE); 50 glutWireSphere(1.0, 20, 10); 51 glEndList(); 52 53 bases[1] = glGenLists(1); 54 glNewList(bases[1], GL_COMPILE); 55 glutSolidSphere(1.0, 20, 10); 56 glEndList(); 57 58 bases[2] = glGenLists(1); 59 glNewList(bases[2], GL_COMPILE); 60 glutWireCube(1.0); 61 glEndList(); 62 63 bases[3] = glGenLists(1); 64 glNewList(bases[3], GL_COMPILE); 65 glutSolidCube(1.0); 66 glEndList(); 67 68 bases[4] = glGenLists(1); 69 glNewList(bases[4], GL_COMPILE); 70 glutWireTorus(1.0, 1.0, 10, 20); 71 glEndList(); 72 73 bases[5] = glGenLists(1); 74 glNewList(bases[5], GL_COMPILE); 75 glutSolidTorus(1.0, 1.0, 10, 20); 76 glEndList(); 77 78 bases[6] = glGenLists(1); 79 glNewList(bases[6], GL_COMPILE); 80 glutWireIcosahedron(); 81 glEndList(); 82 83 bases[7] = glGenLists(1); 84 glNewList(bases[7], GL_COMPILE); 85 glutSolidIcosahedron(); 86 glEndList(); 87 88 bases[8] = glGenLists(1); 89 glNewList(bases[8], GL_COMPILE); 90 glutWireOctahedron(); 91 glEndList(); 92 93 bases[9] = glGenLists(1); 94 glNewList(bases[9], GL_COMPILE); 95 glutSolidOctahedron(); 96 glEndList(); 97 98 bases[10] = glGenLists(1); 99 glNewList(bases[10], GL_COMPILE); 100 glutWireTetrahedron(); 101 glEndList(); 102 103 bases[11] = glGenLists(1); 104 glNewList(bases[11], GL_COMPILE); 105 glutSolidTetrahedron(); 106 glEndList(); 107 108 bases[12] = glGenLists(1); 109 glNewList(bases[12], GL_COMPILE); 110 glutWireDodecahedron(); 111 glEndList(); 112 113 bases[13] = glGenLists(1); 114 glNewList(bases[13], GL_COMPILE); 115 glutSolidDodecahedron(); 116 glEndList(); 117 118 bases[14] = glGenLists(1); 119 glNewList(bases[14], GL_COMPILE); 120 glutWireCone(5.0, 5.0, 20, 10); 121 glEndList(); 122 123 bases[15] = glGenLists(1); 124 glNewList(bases[15], GL_COMPILE); 125 glutSolidCone(5.0, 5.0, 20, 10); 126 glEndList(); 127 128 bases[16] = glGenLists(1); 129 glNewList(bases[16], GL_COMPILE); 130 glutWireTeapot(1.0); 131 glEndList(); 132 133 bases[17] = glGenLists(1); 134 glNewList(bases[17], GL_COMPILE); 135 glutSolidTeapot(1.0); 136 glEndList(); 137 138 glClearColor(0.0, 0.0, 0.0, 0.0); 139 glClearIndex(0.0); 140} 141 142static void Reshape(int width, int height) 143{ 144 145 glViewport(0, 0, (GLint)width, (GLint)height); 146 147 glMatrixMode(GL_PROJECTION); 148 glLoadIdentity(); 149 glOrtho(-400.0, 400.0, -200.0, 200.0, -400.0, 400.0); 150 glMatrixMode(GL_MODELVIEW); 151} 152 153static void Key2(int key, int x, int y) 154{ 155 156 switch (key) { 157 case GLUT_KEY_LEFT: 158 shiftX -= 20.0; 159 break; 160 case GLUT_KEY_RIGHT: 161 shiftX += 20.0; 162 break; 163 case GLUT_KEY_UP: 164 shiftY += 20.0; 165 break; 166 case GLUT_KEY_DOWN: 167 shiftY -= 20.0; 168 break; 169 default: 170 return; 171 } 172 173 glutPostRedisplay(); 174} 175 176static void Key(unsigned char key, int x, int y) 177{ 178 179 switch (key) { 180 case 27: 181 exit(1); 182 183 case 32: 184 objectIndex++; 185 if (objectIndex > 17) { 186 objectIndex = 0; 187 } 188 break; 189 190 case 'n': 191 shiftZ += 20.0; 192 break; 193 case 'm': 194 shiftZ -= 20.0; 195 break; 196 197 case 'q': 198 scaleX -= 0.1; 199 if (scaleX < 0.1) { 200 scaleX = 0.1; 201 } 202 break; 203 case 'w': 204 scaleX += 0.1; 205 break; 206 case 'a': 207 scaleY -= 0.1; 208 if (scaleY < 0.1) { 209 scaleY = 0.1; 210 } 211 break; 212 case 's': 213 scaleY += 0.1; 214 break; 215 case 'z': 216 scaleZ -= 0.1; 217 if (scaleZ < 0.1) { 218 scaleZ = 0.1; 219 } 220 break; 221 case 'x': 222 scaleZ += 0.1; 223 break; 224 225 case 'e': 226 angleX -= 5.0; 227 if (angleX < 0.0) { 228 angleX = 360.0 + angleX; 229 } 230 break; 231 case 'r': 232 angleX += 5.0; 233 if (angleX > 360.0) { 234 angleX = angleX - 360.0; 235 } 236 break; 237 case 'd': 238 angleY -= 5.0; 239 if (angleY < 0.0) { 240 angleY = 360.0 + angleY; 241 } 242 break; 243 case 'f': 244 angleY += 5.0; 245 if (angleY > 360.0) { 246 angleY = angleY - 360.0; 247 } 248 break; 249 case 'c': 250 angleZ -= 5.0; 251 if (angleZ < 0.0) { 252 angleZ = 360.0 + angleZ; 253 } 254 break; 255 case 'v': 256 angleZ += 5.0; 257 if (angleZ > 360.0) { 258 angleZ = angleZ - 360.0; 259 } 260 break; 261 default: 262 return; 263 } 264 265 glutPostRedisplay(); 266} 267 268static void Draw(void) 269{ 270 271 glClear(GL_COLOR_BUFFER_BIT); 272 273 SetColor(COLOR_WHITE); 274 275 glPushMatrix(); 276 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); 282 283 glCallList(bases[objectIndex]); 284 glPopMatrix(); 285 286 glFlush(); 287 288 if (doubleBuffer) { 289 glutSwapBuffers(); 290 } 291} 292 293static GLenum Args(int argc, char **argv) 294{ 295 GLint i; 296 297 rgb = GL_TRUE; 298 doubleBuffer = GL_FALSE; 299 300 for (i = 1; i < argc; i++) { 301 if (strcmp(argv[i], "-ci") == 0) { 302 rgb = GL_FALSE; 303 } else if (strcmp(argv[i], "-rgb") == 0) { 304 rgb = GL_TRUE; 305 } else if (strcmp(argv[i], "-sb") == 0) { 306 doubleBuffer = GL_FALSE; 307 } else if (strcmp(argv[i], "-db") == 0) { 308 doubleBuffer = GL_TRUE; 309 } else { 310 printf("%s (Bad option).\n", argv[i]); 311 return GL_FALSE; 312 } 313 } 314 return GL_TRUE; 315} 316 317int main(int argc, char **argv) 318{ 319 glutInit(&argc, argv); 320 321 if (Args(argc, argv) == GL_FALSE) { 322 exit(1); 323 } 324 325 glutInitWindowPosition(0, 0); glutInitWindowSize( 400, 400); 326 327 windType = (rgb) ? GLUT_RGB : GLUT_INDEX; 328 windType |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; 329 glutInitDisplayMode(windType); 330 331 if (glutCreateWindow("Font Test") == GL_FALSE) { 332 exit(1); 333 } 334 335 InitMap(); 336 337 Init(); 338 339 glutReshapeFunc(Reshape); 340 glutKeyboardFunc(Key); 341 glutSpecialFunc(Key2); 342 glutDisplayFunc(Draw); 343 glutMainLoop(); 344 return 0; 345} 346