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.
- */
-
- /* shadeModel.c - open a window, clear the background, and render a
- * line, a triangle fan and a quad strip using flat/smooth shading.
- *
- * SPACE key - toggle between flat/smooth shading
- * ESCAPE key - exit program
- */
-
- #include <GL/gl.h>
- #include <GL/glut.h>
-
- #include <stdio.h>
-
- /* Function Prototypes */
-
- GLvoid initgfx( GLvoid );
- GLvoid keyboard( GLubyte, GLint, GLint );
- GLvoid drawScene( GLvoid );
-
- void printHelp( char * );
-
- /* Global Definitions */
-
- #define KEY_ESC 27 /* ascii value for the escape key */
-
- static GLint flatShading = GL_FALSE;
-
- void
- main( int argc, char *argv[] )
- {
- GLsizei width, height;
-
- glutInit( &argc, argv );
-
- width = glutGet( GLUT_SCREEN_WIDTH );
- height = glutGet( GLUT_SCREEN_HEIGHT );
- glutInitWindowPosition( width / 4, height / 4 );
- glutInitWindowSize( width / 2, height / 2 );
- glutInitDisplayMode( GLUT_RGBA );
- glutCreateWindow( argv[0] );
-
- initgfx();
-
- glutKeyboardFunc( keyboard );
- glutDisplayFunc( drawScene );
-
- printHelp( argv[0] );
-
- glutMainLoop();
- }
-
- void
- printHelp( char *progname )
- {
- fprintf(stdout, "\n%s - demonstrates shading models\n\n"
- "SPACE Key - toggle between flat/smooth shading\n"
- "Escape Key - exit the program\n\n",
- progname);
- }
-
- GLvoid
- initgfx( GLvoid )
- {
- glClearColor( 0.0, 0.0, 1.0, 1.0 );
-
- glOrtho( 0.0, 1.0, 0.0, 1.0, -1.0, 1.0 );
- }
-
- GLvoid
- keyboard( GLubyte key, GLint x, GLint y )
- {
- switch (key) {
- case ' ':
- flatShading = !flatShading;
- if (flatShading)
- glShadeModel(GL_FLAT);
- else
- glShadeModel(GL_SMOOTH);
- glutPostRedisplay();
- break;
- case KEY_ESC: /* Exit whenever the Escape key is pressed */
- exit(0);
- }
- }
-
- GLvoid
- drawScene( GLvoid )
- {
- static GLfloat blackColor[] = { 0.0, 0.0, 0.0 };
- static GLfloat redColor[] = { 1.0, 0.0, 0.0 };
- static GLfloat purpleColor[] = { 1.0, 0.0, 1.0 };
- static GLfloat yellowColor[] = { 1.0, 1.0, 0.0 };
- static GLfloat whiteColor[] = { 1.0, 1.0, 1.0 };
- static GLfloat darkgreenColor[] = { 0.0, 0.5, 0.0 };
-
- glClear( GL_COLOR_BUFFER_BIT );
-
- /* Draw a point */
- glBegin( GL_POINTS );
- glColor3fv( whiteColor );
- glVertex2f( 0.3, 0.85 );
- glColor3f( 1.0, 0.50, 0.0 ); /* Orange */
- glVertex2f( 3.0, 9.65 ); /* This point is clipped */
- glEnd();
-
- /* Gouraud shade a line */
- glBegin( GL_LINES );
- glColor3f( 1.0, 0.0, 0.0 ); /* Red */
- glVertex2f( 0.1, 0.1 );
- glColor3fv( yellowColor );
- glVertex2f( 0.2, 0.9 );
- glEnd();
-
- /* Gouraud shade a polygon */
- glBegin( GL_POLYGON );
- glColor3fv( purpleColor );
- glVertex2f( 0.5, 0.1 );
- glColor3fv( redColor );
- glVertex2f( 1.0, 0.4 );
- glColor3fv( blackColor );
- glVertex2f( 0.9, 1.0 );
- glColor3fv( darkgreenColor );
- glVertex2f( 0.3, 0.8 );
- glColor3fv( whiteColor );
- glVertex2f( 0.1, 0.5 );
- glEnd();
-
- /* Draw a triangle fan */
- glBegin( GL_TRIANGLE_FAN );
- glColor3fv( blackColor );
- glVertex2f( 0.4, 0.4 );
- glColor3fv( redColor );
- glVertex2f( 0.3, 0.4 );
- glColor3f( 0.0, 0.0, 1.0 ); /* blue */
- glVertex2f( 0.4, 0.5 );
- glColor3fv( yellowColor );
- glVertex2f( 0.5, 0.5 );
- glColor3fv( whiteColor );
- glVertex2f( 0.5, 0.4 );
- glColor3fv( darkgreenColor );
- glVertex2f( 0.4, 0.3 );
- glEnd();
-
- glFlush();
- }
-