/* * Copyright (c) 1996-1999 Silicon Graphics, Inc. All rights reserved. * * THE SOFTWARE IS PROVIDED "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 BE LIABLE FOR ANY SPECIAL, INCIDENTAL, * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE * POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ /* clearcolor.c - open a window and clear the background. * Set up callbacks to handle keyboard input. * * F1 key - print help information * SPACE key - generates a random background color * Escape Key - exit program */ #include /* includes gl.h, glu.h */ #include #include #include "checkerror.h" #include "random.h" /* Function Prototypes */ GLvoid initgfx( GLvoid ); GLvoid keyboard( GLubyte, GLint, GLint ); GLvoid specialkeys( GLint, GLint, GLint ); GLvoid drawScene( GLvoid ); void printHelp( char * ); /* Global Variables */ static char *progname; /* Global Definitions */ #define KEY_ESC 27 /* ascii value for the escape key */ void main( int argc, char *argv[] ) { GLsizei width, height; glutInit( &argc, argv ); /* create a window that is 1/4 the size of the screen, * and position it in the middle of the screen. */ 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 ); glutSpecialFunc( specialkeys ); glutDisplayFunc( drawScene ); progname = argv[0]; printHelp( progname ); glutMainLoop(); } void printHelp( char *progname ) { fprintf(stdout, "\n%s - demonstrates how to handle keyboard input\n\n" "F1 key - print help information\n" "SPACE Key - generates a random background color\n" "Escape Key - exit the program\n\n", progname); } GLvoid initgfx( GLvoid ) { /* set clear color to magenta */ } GLvoid keyboard( GLubyte key, GLint x, GLint y ) { switch (key) { case ' ': /* SPACE key */ /* generate a random background color using RANDOM in random.h */ break; case 'r': case 'R': /* generate a red background color */ break; case 'g': case 'G': /* generate a green background color */ break; case 'b': case 'B': /* generate a blue color */ break; case KEY_ESC: /* Exit when the Escape key is pressed */ } } GLvoid specialkeys( GLint key, GLint x, GLint y ) { switch (key) { case GLUT_KEY_F1: /* Function key #1 */ /* print help information */ break; } } GLvoid drawScene( GLvoid ) { /* clear window */ checkError( "drawScene" ); glFlush(); }