home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 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.
- */
-
- /* matrixmodes.c - draw a triangle under the effect of a rotation,
- * a translation and a scale; use the matrix stack
- * to ensure that the scene is properly redrawn.
- *
- * Escape Key - exit program
- */
- #include <GL/gl.h>
- #include <GL/glu.h>
- #include <GL/glut.h>
-
- #include <stdio.h>
-
- /* Function Prototypes */
-
- GLvoid initgfx( GLvoid );
- GLvoid keyboard( GLubyte, GLint, GLint );
- GLvoid drawScene( GLvoid );
-
- void drawTriangle( GLfloat red, GLfloat green, GLfloat blue );
-
- void printHelp( char * );
-
- /* Global Definitions */
-
- #define KEY_ESC 27 /* ascii value for the escape key */
-
- 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) + 2, height / 4 );
- glutInitWindowSize( width / 2, height / 2 );
- glutInitDisplayMode( GLUT_RGBA );
- glutCreateWindow( argv[0] );
-
- initgfx();
-
- glutKeyboardFunc( keyboard );
- glutDisplayFunc( drawScene );
-
- printHelp( argv[0] );
-
- glMatrixMode( GL_PROJECTION );
- gluPerspective( 45.0, (GLdouble) width/ (GLdouble)height, 3.0, 7.0 );
- glMatrixMode( GL_MODELVIEW );
-
- glutMainLoop();
- }
-
- void
- printHelp( char *progname )
- {
- fprintf(stdout,
- "\n%s - demonstrates use of matrix modes and stacks\n\n"
- "Escape Key - exit the program\n\n",
- progname);
- }
-
- GLvoid
- initgfx( GLvoid )
- {
- glClearColor( 0.0, 0.0, 1.0, 1.0 );
- glShadeModel( GL_FLAT );
- }
-
- GLvoid
- keyboard( GLubyte key, GLint x, GLint y )
- {
- switch (key) {
- case KEY_ESC: /* Exit whenever the Escape key is pressed */
- exit(0);
- }
- }
-
- GLvoid
- drawTriangle( GLfloat red, GLfloat green, GLfloat blue )
- {
- glColor3f( red, green, blue );
- glBegin( GL_TRIANGLES );
- glVertex2f( -0.5, -0.5 );
- glVertex2f( 0.5, -0.5 );
- glVertex2f( 0.0, 0.5 );
- glEnd();
- }
-
- GLvoid
- drawScene( GLvoid )
- {
- glClear( GL_COLOR_BUFFER_BIT );
-
- glPushMatrix();
- /* Translate the origin so that it is between the near and far
- * clipping planes.
- */
- glTranslatef( 0.0, 0.0, -5.0 );
-
- /* draw a black triangle centered at the origin */
- drawTriangle( 0.0, 0.0, 0.0 );
-
- /* Draw x and y axes to show the origin */
- XYaxes();
-
- /* move over a bit and draw another triangle */
- glTranslatef( 0.5, 0.0, 0.0 );
- drawTriangle( 0.3, 0.3, 0.3 );
-
- /* move over a bit and draw a rotated triangle */
- glTranslatef( 0.5, 0.0, 0.0 );
-
- /* Rotate 60 degrees clockwise around the positive Z axis */
- glRotatef( -15.0, 0.0, 0.0, 1.0 );
- drawTriangle( 0.7, 0.7, 0.7 );
-
- /* move over a bit and draw a scaled triangle */
- glTranslatef( 0.5, 0.0, 0.0 );
-
- /* Scale the triangle by one-half in all dimensions */
- glScalef( -0.5, 0.5, 0.5 );
- drawTriangle( 1.0, 1.0, 1.0 ); /* draw green triangle */
- XYaxes();
-
- glPopMatrix();
-
- glFlush();
- }
-