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.
- */
-
- /* polygonMode.c - open a window, clear the background, and render
- * a polygon using different polygon modes
- *
- * Escape key - exit the program
- */
- #include <GL/gl.h>
- #include <GL/glu.h>
- #include <GL/glut.h>
-
- #include <math.h>
- #include <stdio.h>
-
- /* Function Prototypes */
-
- GLvoid initgfx( GLvoid );
- GLvoid drawScene( GLvoid );
- GLvoid reshape( GLsizei, GLsizei );
- GLvoid keyboard( GLubyte, GLint, GLint );
-
- 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/4, height/4 );
- glutInitWindowSize( width/2, height/2 );
- glutInitDisplayMode( GLUT_RGBA );
- glutCreateWindow( argv[0] );
-
- initgfx();
-
- glutKeyboardFunc( keyboard );
- glutReshapeFunc( reshape );
- glutDisplayFunc( drawScene );
-
- printHelp( argv[0] );
-
- glutMainLoop();
- }
-
- GLvoid
- printHelp( char *progname )
- {
- fprintf(stdout, "\n%s - demonstrates polygon modes\n\n"
- "Escape key - exit the program\n\n",
- progname
- );
- }
-
- GLvoid
- initgfx( GLvoid )
- {
- glClearColor( 0.0, 0.0, 0.0, 1.0 );
-
- /* make points and lines really big
- * so that they will be easy to see
- */
- glLineWidth( 3.5 );
- glPointSize( 8.5 );
- }
-
- GLvoid
- keyboard( GLubyte key, GLint x, GLint y )
- {
- switch (key) {
- case KEY_ESC: /* Exit whenever the Escape key is pressed */
- exit(0);
- }
- }
-
- GLvoid
- reshape( GLsizei width, GLsizei height )
- {
- GLdouble aspect;
-
- glViewport( 0, 0, width, height );
-
- aspect = (GLdouble) width / (GLdouble) height;
-
- glMatrixMode( GL_PROJECTION );
- glLoadIdentity();
- glOrtho( -2.0, 2.0, -2.0, 2.0, -1.0, 1.0 );
- glMatrixMode( GL_MODELVIEW );
- glLoadIdentity();
- }
-
- GLvoid
- drawScene( GLvoid )
- {
- static GLfloat purpleColor[] = { 1.0, 0.0, 1.0 };
- static GLfloat v[] = { 0.5, 0.1 };
-
- glClear( GL_COLOR_BUFFER_BIT );
-
- /* Draw a purple filled polygon */
- glColor3fv( purpleColor );
- glBegin( GL_POLYGON );
- glVertex2fv( v );
- glVertex2f( 1.0, 0.4 );
- glVertex2f( 0.9, 1.0 );
- glVertex2f( 0.3, 0.8 );
- glVertex2f( 0.1, 0.5 );
- glEnd();
-
- /* draw the back of this polygon (vertices specified in
- * clockwise order) using line mode */
- glPolygonMode( GL_BACK, GL_LINE );
- glColor3f( 1.0, 1.0, 1.0 );
- glBegin( GL_POLYGON );
- glVertex2f( 0.1, 0.5 );
- glVertex2f( 0.3, 0.8 );
- glVertex2f( 0.9, 1.0 );
- glVertex2f( 1.0, 0.4 );
- glVertex2fv( v );
- glEnd();
-
- /* change to clockwise, front-facing polygons;
- * draw front facing polygons as points */
- glFrontFace( GL_CW );
- glPolygonMode( GL_FRONT, GL_POINT );
- glBegin( GL_POLYGON );
- glVertex2f( -1.0, 1.0 );
- glVertex2f( 1.0, 1.0 );
- glVertex2f( 1.0, -1.0 );
- glVertex2f( -1.0, -1.0 );
- glEnd();
-
- /* return to default modes */
- glFrontFace( GL_CCW );
- glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
-
- glFlush();
- }
-