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.
- */
-
- /* grid.c - open a window, clear the background, and render a
- * grid of points or lines centered around the origin.
- *
- * SPACE key - toggle between point/line grid
- * 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 pointGrid = GL_TRUE;
-
- 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 simple rendering primitives\n\n"
- "SPACE Key - toggle between point/line grid\n"
- "Escape Key - exit the program\n\n",
- progname);
- }
-
- GLvoid
- initgfx( GLvoid )
- {
- glClearColor( 0.0, 0.0, 1.0, 1.0 );
-
- glOrtho( -2.0, 2.0, -2.0, 2.0, -1.0, 1.0 );
- }
-
- GLvoid
- keyboard( GLubyte key, GLint x, GLint y )
- {
- switch (key) {
- case ' ':
- pointGrid = !pointGrid;
- glutPostRedisplay();
- break;
- case KEY_ESC: /* Exit whenever the Escape key is pressed */
- exit(0);
- }
- }
-
- GLvoid
- drawScene( GLvoid )
- {
- GLfloat x, y;
-
- glClear( GL_COLOR_BUFFER_BIT );
-
- glColor3f( 1.0, 1.0, 1.0 );
-
- if (pointGrid) {
- /* Render a grid composed of evenly spaced points */
- glPointSize( 3.5 );
- glBegin( GL_POINTS );
- for ( x = -1.0; x < 1.1; x += 0.1 )
- for ( y = -1.0; y < 1.1; y += 0.1 )
- glVertex2f( x, y );
- glEnd();
- } else {
- /* Draw a line grid centered at the origin */
- glLineWidth( 2.5 );
- glBegin( GL_LINES );
- for ( x = -1.0; x < 1.1; x += 0.1 ) {/* draw vertical lines */
- glVertex2f( x, -1.0 );
- glVertex2f( x, 1.0 );
- }
- for ( y = -1.0; y < 1.1; y += 0.1 ) {/* draw horizontal lines */
- glVertex2f( -1.0, y );
- glVertex2f( 1.0, y );
- }
- glEnd();
- }
-
- glFlush();
- }
-