home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1993, 1996, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
-
- /* enterprise.c - creates a model of the Enterprise
- *
- * Author: Benedikt Kesseler
- * benedikt@munich.sgi.com
- */
- #include <math.h> /* for fmodf */
- #include <stdlib.h> /* for NULL */
-
- #include <GL/gl.h>
- #include <GL/glu.h>
- #include <GL/glut.h>
-
- /* Function Prototypes */
-
- GLvoid initgfx();
- GLvoid animate( GLvoid );
- GLvoid visibility( GLint );
- GLvoid keyboard( GLubyte, GLint, GLint );
- GLvoid reshape( GLsizei, GLsizei );
- GLvoid drawScene( GLvoid );
-
- /* Global Definitions */
-
- #define KEY_ESC 27 /* ascii value for the escape key */
-
- /* Global Variables */
-
- static GLfloat angle1 = 0.0, angle2 = 0.0; /* controls rotation */
-
- void
- main( int argc, char *argv[] )
- {
- GLsizei width, height;
-
- glutInit( &argc, argv );
-
- width = glutGet( GLUT_SCREEN_WIDTH );
- height = glutGet( GLUT_SCREEN_HEIGHT );
- glutInitWindowPosition( (width / 2) + 4, height / 4 );
- glutInitWindowSize( (width / 2) - 4, height / 2 );
- glutInitDisplayMode( GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE );
- glutCreateWindow( argv[0] );
-
- initgfx();
-
- glutIdleFunc( animate );
- glutVisibilityFunc( visibility );
- glutKeyboardFunc( keyboard );
- glutReshapeFunc( reshape );
- glutDisplayFunc( drawScene );
-
- glutMainLoop();
- }
-
- GLvoid
- initgfx()
- {
- glClearColor( 0.0, 0.0, 0.0, 1.0 );
- glEnable( GL_DEPTH_TEST );
- }
-
- GLvoid
- reshape( GLsizei width, GLsizei height )
- {
- GLdouble aspect;
-
- glViewport( 0, 0, width, height );
-
- aspect = (GLdouble) width / (GLdouble) height;
-
- /* Set the matrix mode to affect the Projection matrix */
- glMatrixMode( GL_PROJECTION );
-
- /* Clear the current Projection matrix */
- glLoadIdentity();
-
- /* Multiply the new perspective projection on the matrix */
- gluPerspective( 90.0, aspect, 3.0, 37.0 );
-
- /* Return to the ModelView mode */
- glMatrixMode( GL_MODELVIEW );
- }
-
- GLvoid
- keyboard( GLubyte key, GLint x, GLint y )
- {
- switch (key) {
- case KEY_ESC: /* Exit when the Escape key is pressed */
- exit(0);
- }
- }
-
- GLvoid
- animate( GLvoid )
- {
- /* update the rotation for each scene */
- angle1 = fmodf( (angle1 + 1.0), 360.0 );
- angle2 = fmodf( (angle2 + 2.0), 360.0 );
-
- glutPostRedisplay(); /* Tell GLUT to redraw the scene */
- }
-
- GLvoid
- visibility( int state )
- {
- if (state == GLUT_VISIBLE) {
- glutIdleFunc( animate );
- } else {
- glutIdleFunc( NULL );
- }
- }
-
- GLvoid
- drawScene( GLvoid )
- {
- static GLfloat redColor[] = { 1.0, 0.0, 0.0 };
- static GLfloat darkgreenColor[] = { 0.0, 0.5, 0.0 };
- static GLfloat whiteColor[] = { 1.0, 1.0, 1.0 };
-
- glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- /* Save the Identity matrix that's on the ModelView
- * matrix stack
- */
-
- glPushMatrix();
-
- gluLookAt(0.0, .0, 25.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
-
- glRotatef(angle1, 0.0, 1.0, 0.0);
- glRotatef(angle2, 1.0, 0.0, 1.0);
-
- glPushMatrix();
-
- glScalef(5.0, 0.6, 5.0);
- glColor3fv( whiteColor );
- glutSolidSphere( 2.0, 15, 15 );
-
- glPopMatrix();
-
- glColor3fv( darkgreenColor );
- glutWireSphere( 3.0, 15, 15 );
-
- glPushMatrix();
-
- glColor3fv( redColor );
- glRotatef(90.0, 0.0, 0.0, 1.0);
- glTranslatef(4.0, 20.0, 5.0);
- WireCylinder(1., 10.0);
- glTranslatef(0.0, 0.0, -10.0);
- WireCylinder(1., 10.0);
-
- glPopMatrix();
-
- glTranslatef(0.0, -5.0, 0.0);
- glutWireTeapot(4.0);
-
- glPopMatrix();
-
- glutSwapBuffers();
- }
-