132001f49Smrg/* 232001f49Smrg * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. 332001f49Smrg * 432001f49Smrg * Permission to use, copy, modify, distribute, and sell this software and 532001f49Smrg * its documentation for any purpose is hereby granted without fee, provided 632001f49Smrg * that (i) the above copyright notices and this permission notice appear in 732001f49Smrg * all copies of the software and related documentation, and (ii) the name of 832001f49Smrg * Silicon Graphics may not be used in any advertising or 932001f49Smrg * publicity relating to the software without the specific, prior written 1032001f49Smrg * permission of Silicon Graphics. 1132001f49Smrg * 1232001f49Smrg * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF 1332001f49Smrg * ANY KIND, 1432001f49Smrg * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 1532001f49Smrg * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 1632001f49Smrg * 1732001f49Smrg * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR 1832001f49Smrg * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, 1932001f49Smrg * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 2032001f49Smrg * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 2132001f49Smrg * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 2232001f49Smrg * OF THIS SOFTWARE. 2332001f49Smrg */ 2432001f49Smrg 2532001f49Smrg#include <stdio.h> 2632001f49Smrg#include <string.h> 2732001f49Smrg#include <stdlib.h> 2832001f49Smrg#include "glut_wrap.h" 2932001f49Smrg 3032001f49Smrg 3132001f49Smrg#define OPENGL_WIDTH 24 3232001f49Smrg#define OPENGL_HEIGHT 13 3332001f49Smrg 3432001f49Smrg 3532001f49SmrgGLenum rgb, doubleBuffer, windType; 3632001f49SmrgGLint objectIndex = 0; 3732001f49SmrgGLuint bases[20]; 3832001f49Smrgfloat angleX = 0.0, angleY = 0.0, angleZ = 0.0; 3932001f49Smrgfloat scaleX = 1.0, scaleY = 1.0, scaleZ = 1.0; 4032001f49Smrgfloat shiftX = 0.0, shiftY = 0.0, shiftZ = 0.0; 4132001f49Smrg 4232001f49Smrg 4332001f49Smrg#include "tkmap.c" 4432001f49Smrg 4532001f49Smrgstatic void Init(void) 4632001f49Smrg{ 4732001f49Smrg 4832001f49Smrg bases[0] = glGenLists(1); 4932001f49Smrg glNewList(bases[0], GL_COMPILE); 5032001f49Smrg glutWireSphere(1.0, 20, 10); 5132001f49Smrg glEndList(); 5232001f49Smrg 5332001f49Smrg bases[1] = glGenLists(1); 5432001f49Smrg glNewList(bases[1], GL_COMPILE); 5532001f49Smrg glutSolidSphere(1.0, 20, 10); 5632001f49Smrg glEndList(); 5732001f49Smrg 5832001f49Smrg bases[2] = glGenLists(1); 5932001f49Smrg glNewList(bases[2], GL_COMPILE); 6032001f49Smrg glutWireCube(1.0); 6132001f49Smrg glEndList(); 6232001f49Smrg 6332001f49Smrg bases[3] = glGenLists(1); 6432001f49Smrg glNewList(bases[3], GL_COMPILE); 6532001f49Smrg glutSolidCube(1.0); 6632001f49Smrg glEndList(); 6732001f49Smrg 6832001f49Smrg bases[4] = glGenLists(1); 6932001f49Smrg glNewList(bases[4], GL_COMPILE); 7032001f49Smrg glutWireTorus(1.0, 1.0, 10, 20); 7132001f49Smrg glEndList(); 7232001f49Smrg 7332001f49Smrg bases[5] = glGenLists(1); 7432001f49Smrg glNewList(bases[5], GL_COMPILE); 7532001f49Smrg glutSolidTorus(1.0, 1.0, 10, 20); 7632001f49Smrg glEndList(); 7732001f49Smrg 7832001f49Smrg bases[6] = glGenLists(1); 7932001f49Smrg glNewList(bases[6], GL_COMPILE); 8032001f49Smrg glutWireIcosahedron(); 8132001f49Smrg glEndList(); 8232001f49Smrg 8332001f49Smrg bases[7] = glGenLists(1); 8432001f49Smrg glNewList(bases[7], GL_COMPILE); 8532001f49Smrg glutSolidIcosahedron(); 8632001f49Smrg glEndList(); 8732001f49Smrg 8832001f49Smrg bases[8] = glGenLists(1); 8932001f49Smrg glNewList(bases[8], GL_COMPILE); 9032001f49Smrg glutWireOctahedron(); 9132001f49Smrg glEndList(); 9232001f49Smrg 9332001f49Smrg bases[9] = glGenLists(1); 9432001f49Smrg glNewList(bases[9], GL_COMPILE); 9532001f49Smrg glutSolidOctahedron(); 9632001f49Smrg glEndList(); 9732001f49Smrg 9832001f49Smrg bases[10] = glGenLists(1); 9932001f49Smrg glNewList(bases[10], GL_COMPILE); 10032001f49Smrg glutWireTetrahedron(); 10132001f49Smrg glEndList(); 10232001f49Smrg 10332001f49Smrg bases[11] = glGenLists(1); 10432001f49Smrg glNewList(bases[11], GL_COMPILE); 10532001f49Smrg glutSolidTetrahedron(); 10632001f49Smrg glEndList(); 10732001f49Smrg 10832001f49Smrg bases[12] = glGenLists(1); 10932001f49Smrg glNewList(bases[12], GL_COMPILE); 11032001f49Smrg glutWireDodecahedron(); 11132001f49Smrg glEndList(); 11232001f49Smrg 11332001f49Smrg bases[13] = glGenLists(1); 11432001f49Smrg glNewList(bases[13], GL_COMPILE); 11532001f49Smrg glutSolidDodecahedron(); 11632001f49Smrg glEndList(); 11732001f49Smrg 11832001f49Smrg bases[14] = glGenLists(1); 11932001f49Smrg glNewList(bases[14], GL_COMPILE); 12032001f49Smrg glutWireCone(5.0, 5.0, 20, 10); 12132001f49Smrg glEndList(); 12232001f49Smrg 12332001f49Smrg bases[15] = glGenLists(1); 12432001f49Smrg glNewList(bases[15], GL_COMPILE); 12532001f49Smrg glutSolidCone(5.0, 5.0, 20, 10); 12632001f49Smrg glEndList(); 12732001f49Smrg 12832001f49Smrg bases[16] = glGenLists(1); 12932001f49Smrg glNewList(bases[16], GL_COMPILE); 13032001f49Smrg glutWireTeapot(1.0); 13132001f49Smrg glEndList(); 13232001f49Smrg 13332001f49Smrg bases[17] = glGenLists(1); 13432001f49Smrg glNewList(bases[17], GL_COMPILE); 13532001f49Smrg glutSolidTeapot(1.0); 13632001f49Smrg glEndList(); 13732001f49Smrg 13832001f49Smrg glClearColor(0.0, 0.0, 0.0, 0.0); 13932001f49Smrg glClearIndex(0.0); 14032001f49Smrg} 14132001f49Smrg 14232001f49Smrgstatic void Reshape(int width, int height) 14332001f49Smrg{ 14432001f49Smrg 14532001f49Smrg glViewport(0, 0, (GLint)width, (GLint)height); 14632001f49Smrg 14732001f49Smrg glMatrixMode(GL_PROJECTION); 14832001f49Smrg glLoadIdentity(); 14932001f49Smrg glOrtho(-400.0, 400.0, -200.0, 200.0, -400.0, 400.0); 15032001f49Smrg glMatrixMode(GL_MODELVIEW); 15132001f49Smrg} 15232001f49Smrg 15332001f49Smrgstatic void Key2(int key, int x, int y) 15432001f49Smrg{ 15532001f49Smrg 15632001f49Smrg switch (key) { 15732001f49Smrg case GLUT_KEY_LEFT: 15832001f49Smrg shiftX -= 20.0; 15932001f49Smrg break; 16032001f49Smrg case GLUT_KEY_RIGHT: 16132001f49Smrg shiftX += 20.0; 16232001f49Smrg break; 16332001f49Smrg case GLUT_KEY_UP: 16432001f49Smrg shiftY += 20.0; 16532001f49Smrg break; 16632001f49Smrg case GLUT_KEY_DOWN: 16732001f49Smrg shiftY -= 20.0; 16832001f49Smrg break; 16932001f49Smrg default: 17032001f49Smrg return; 17132001f49Smrg } 17232001f49Smrg 17332001f49Smrg glutPostRedisplay(); 17432001f49Smrg} 17532001f49Smrg 17632001f49Smrgstatic void Key(unsigned char key, int x, int y) 17732001f49Smrg{ 17832001f49Smrg 17932001f49Smrg switch (key) { 18032001f49Smrg case 27: 18132001f49Smrg exit(1); 18232001f49Smrg 18332001f49Smrg case 32: 18432001f49Smrg objectIndex++; 18532001f49Smrg if (objectIndex > 17) { 18632001f49Smrg objectIndex = 0; 18732001f49Smrg } 18832001f49Smrg break; 18932001f49Smrg 19032001f49Smrg case 'n': 19132001f49Smrg shiftZ += 20.0; 19232001f49Smrg break; 19332001f49Smrg case 'm': 19432001f49Smrg shiftZ -= 20.0; 19532001f49Smrg break; 19632001f49Smrg 19732001f49Smrg case 'q': 19832001f49Smrg scaleX -= 0.1; 19932001f49Smrg if (scaleX < 0.1) { 20032001f49Smrg scaleX = 0.1; 20132001f49Smrg } 20232001f49Smrg break; 20332001f49Smrg case 'w': 20432001f49Smrg scaleX += 0.1; 20532001f49Smrg break; 20632001f49Smrg case 'a': 20732001f49Smrg scaleY -= 0.1; 20832001f49Smrg if (scaleY < 0.1) { 20932001f49Smrg scaleY = 0.1; 21032001f49Smrg } 21132001f49Smrg break; 21232001f49Smrg case 's': 21332001f49Smrg scaleY += 0.1; 21432001f49Smrg break; 21532001f49Smrg case 'z': 21632001f49Smrg scaleZ -= 0.1; 21732001f49Smrg if (scaleZ < 0.1) { 21832001f49Smrg scaleZ = 0.1; 21932001f49Smrg } 22032001f49Smrg break; 22132001f49Smrg case 'x': 22232001f49Smrg scaleZ += 0.1; 22332001f49Smrg break; 22432001f49Smrg 22532001f49Smrg case 'e': 22632001f49Smrg angleX -= 5.0; 22732001f49Smrg if (angleX < 0.0) { 22832001f49Smrg angleX = 360.0 + angleX; 22932001f49Smrg } 23032001f49Smrg break; 23132001f49Smrg case 'r': 23232001f49Smrg angleX += 5.0; 23332001f49Smrg if (angleX > 360.0) { 23432001f49Smrg angleX = angleX - 360.0; 23532001f49Smrg } 23632001f49Smrg break; 23732001f49Smrg case 'd': 23832001f49Smrg angleY -= 5.0; 23932001f49Smrg if (angleY < 0.0) { 24032001f49Smrg angleY = 360.0 + angleY; 24132001f49Smrg } 24232001f49Smrg break; 24332001f49Smrg case 'f': 24432001f49Smrg angleY += 5.0; 24532001f49Smrg if (angleY > 360.0) { 24632001f49Smrg angleY = angleY - 360.0; 24732001f49Smrg } 24832001f49Smrg break; 24932001f49Smrg case 'c': 25032001f49Smrg angleZ -= 5.0; 25132001f49Smrg if (angleZ < 0.0) { 25232001f49Smrg angleZ = 360.0 + angleZ; 25332001f49Smrg } 25432001f49Smrg break; 25532001f49Smrg case 'v': 25632001f49Smrg angleZ += 5.0; 25732001f49Smrg if (angleZ > 360.0) { 25832001f49Smrg angleZ = angleZ - 360.0; 25932001f49Smrg } 26032001f49Smrg break; 26132001f49Smrg default: 26232001f49Smrg return; 26332001f49Smrg } 26432001f49Smrg 26532001f49Smrg glutPostRedisplay(); 26632001f49Smrg} 26732001f49Smrg 26832001f49Smrgstatic void Draw(void) 26932001f49Smrg{ 27032001f49Smrg 27132001f49Smrg glClear(GL_COLOR_BUFFER_BIT); 27232001f49Smrg 27332001f49Smrg SetColor(COLOR_WHITE); 27432001f49Smrg 27532001f49Smrg glPushMatrix(); 27632001f49Smrg 27732001f49Smrg glTranslatef(shiftX, shiftY, shiftZ); 27832001f49Smrg glRotatef(angleX, 1.0, 0.0, 0.0); 27932001f49Smrg glRotatef(angleY, 0.0, 1.0, 0.0); 28032001f49Smrg glRotatef(angleZ, 0.0, 0.0, 1.0); 28132001f49Smrg glScalef(scaleX, scaleY, scaleZ); 28232001f49Smrg 28332001f49Smrg glCallList(bases[objectIndex]); 28432001f49Smrg glPopMatrix(); 28532001f49Smrg 28632001f49Smrg glFlush(); 28732001f49Smrg 28832001f49Smrg if (doubleBuffer) { 28932001f49Smrg glutSwapBuffers(); 29032001f49Smrg } 29132001f49Smrg} 29232001f49Smrg 29332001f49Smrgstatic GLenum Args(int argc, char **argv) 29432001f49Smrg{ 29532001f49Smrg GLint i; 29632001f49Smrg 29732001f49Smrg rgb = GL_TRUE; 29832001f49Smrg doubleBuffer = GL_FALSE; 29932001f49Smrg 30032001f49Smrg for (i = 1; i < argc; i++) { 30132001f49Smrg if (strcmp(argv[i], "-ci") == 0) { 30232001f49Smrg rgb = GL_FALSE; 30332001f49Smrg } else if (strcmp(argv[i], "-rgb") == 0) { 30432001f49Smrg rgb = GL_TRUE; 30532001f49Smrg } else if (strcmp(argv[i], "-sb") == 0) { 30632001f49Smrg doubleBuffer = GL_FALSE; 30732001f49Smrg } else if (strcmp(argv[i], "-db") == 0) { 30832001f49Smrg doubleBuffer = GL_TRUE; 30932001f49Smrg } else { 31032001f49Smrg printf("%s (Bad option).\n", argv[i]); 31132001f49Smrg return GL_FALSE; 31232001f49Smrg } 31332001f49Smrg } 31432001f49Smrg return GL_TRUE; 31532001f49Smrg} 31632001f49Smrg 31732001f49Smrgint main(int argc, char **argv) 31832001f49Smrg{ 31932001f49Smrg glutInit(&argc, argv); 32032001f49Smrg 32132001f49Smrg if (Args(argc, argv) == GL_FALSE) { 32232001f49Smrg exit(1); 32332001f49Smrg } 32432001f49Smrg 32532001f49Smrg glutInitWindowPosition(0, 0); glutInitWindowSize( 400, 400); 32632001f49Smrg 32732001f49Smrg windType = (rgb) ? GLUT_RGB : GLUT_INDEX; 32832001f49Smrg windType |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; 32932001f49Smrg glutInitDisplayMode(windType); 33032001f49Smrg 33132001f49Smrg if (glutCreateWindow("Font Test") == GL_FALSE) { 33232001f49Smrg exit(1); 33332001f49Smrg } 33432001f49Smrg 33532001f49Smrg InitMap(); 33632001f49Smrg 33732001f49Smrg Init(); 33832001f49Smrg 33932001f49Smrg glutReshapeFunc(Reshape); 34032001f49Smrg glutKeyboardFunc(Key); 34132001f49Smrg glutSpecialFunc(Key2); 34232001f49Smrg glutDisplayFunc(Draw); 34332001f49Smrg glutMainLoop(); 34432001f49Smrg return 0; 34532001f49Smrg} 346