home *** CD-ROM | disk | FTP | other *** search
- /*
- * (c) Copyright 1994, Silicon Graphics, Inc.
- * ALL RIGHTS RESERVED
- * Permission to use, copy, modify, and distribute this software for
- * any purpose and without fee is hereby granted, provided that the above
- * copyright notice appear in all copies and that both the copyright notice
- * and this permission notice appear in supporting documentation, and that
- * the name of Silicon Graphics, Inc. not be used in advertising
- * or publicity pertaining to distribution of the software without specific,
- * written prior permission.
- *
- * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
- * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
- * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
- * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
- * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
- * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
- * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
- * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
- * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
- * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * US Government Users Restricted Rights
- * Use, duplication, or disclosure by the Government is subject to
- * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
- * (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 or the DOD or NASA FAR Supplement.
- * Unpublished-- rights reserved under the copyright laws of the
- * United States. Contractor/manufacturer is Silicon Graphics,
- * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
- *
- * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
- */
- #include <GL/gl.h>
- #include <GL/glu.h>
-
- #define GRIDPOINTS 41
-
- static GLboolean __grid_initialized = GL_FALSE;
-
- static GLfloat grid[GRIDPOINTS][GRIDPOINTS][3] = { 0 };
-
- GLvoid
- Checkerboard( GLvoid )
- {
- GLfloat x, y;
- GLboolean useRed = GL_TRUE;
-
- static GLfloat redColor[] = { 1.0, 0.0, 0.0 };
- static GLfloat blackColor[] = { 0.0, 0.0, 0.0 };
-
- glPushAttrib( GL_ENABLE_BIT );
- glDisable( GL_LIGHTING );
- for ( x = -1.0; x < 1.0; x += 0.1 ) {
- useRed = !useRed;
- for ( y = -1.0; y < 1.0; y += 0.1 ) {
- if ( useRed )
- glColor3fv( redColor );
- else
- glColor3fv( blackColor );
- glRectf( x, y, x + 0.1, y + 0.1 );
- useRed = !useRed;
- }
- }
- glPopAttrib( );
- }
-
- GLvoid
- _InitGrid( GLvoid )
- {
- int i, j;
- GLfloat x, y, spacing;
-
- /* Create a flat grid composed of points
- * with the z value = 0
- */
-
- /* spacing = distance between adjacent grid points in x and y */
- spacing = 2.0 / (float)(GRIDPOINTS - 1);
-
- /* x and z range from -1.0 to 1.0 by spacing interval */
- for ( x = -1.0, i = 0; i < GRIDPOINTS; x += spacing, i++ ) {
- for ( y = -1.0, j = 0; j < GRIDPOINTS; y += spacing, j++ ) {
- grid[i][j][0] = x;
- grid[i][j][1] = y;
- grid[i][j][2] = 0.0;
- }
- }
-
- __grid_initialized = GL_TRUE;
- }
-
- GLvoid
- WireGrid( GLvoid )
- {
- register int i, j;
-
- if ( !__grid_initialized )
- _InitGrid();
-
- glNormal3f( 0.0, 0.0, 1.0 );
-
- /* draw vertical lines connecting grid points */
- for ( i = 0; i < (GRIDPOINTS); i++ ) {
- glBegin( GL_LINE_STRIP );
- for ( j = 0; j < (GRIDPOINTS); j++ ) {
- glVertex3fv( &grid[i][j][0] );
- }
- glEnd();
- }
- /* draw horizontal lines connecting grid points */
- for ( j = 0; j < (GRIDPOINTS); j++ ) {
- glBegin( GL_LINE_STRIP );
- for ( i = 0; i < (GRIDPOINTS); i++ ) {
- glVertex3fv( &grid[i][j][0] );
- }
- glEnd();
- }
- }
-
-
- GLvoid
- SolidGrid( GLvoid )
- {
- register int i, j;
-
- if ( !__grid_initialized )
- _InitGrid();
-
- glNormal3f( 0.0, 0.0, 1.0 );
-
- /* Draw quad strips connecting grid points.
- * Grid is drawn column by column,
- * where each column is one quad strip.
- * Every pair of vertices after first two vertices
- * adds a new quad to the strip.
- */
- for ( i = 0; i < (GRIDPOINTS - 1); i++ ) {
- glBegin( GL_QUAD_STRIP );
- for ( j = 0; j < (GRIDPOINTS); j++ ) {
- glVertex3fv( &grid[i][j][0] );
- glVertex3fv( &grid[i + 1][j][0] );
- }
- glEnd();
- }
- }
-
- /**************************************************************************
- * Quit() - convenience function for exiting programs
- **************************************************************************/
-
- GLvoid
- Quit( GLvoid )
- {
- exit( 0 );
- }
-