home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / tutorials / custEducation / opengl1 / examples / transformations / perspectiveRotate.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-11  |  2.6 KB  |  113 lines

  1. /*
  2.  * Copyright 1993, 1996, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17.  
  18. /* perspectiveRotate.c - rotate the line grid around the X axis, 
  19.  *    making it an object in '3D'.  View it using a perspective projection.
  20.  *
  21.  *    Escape Key    - exit program
  22.  */
  23. #include <GL/gl.h>
  24. #include <GL/glu.h>
  25. #include <GL/glut.h>
  26.  
  27. #include <stdio.h>
  28.  
  29. /*  Function Prototypes  */
  30.  
  31. GLvoid  initgfx( GLvoid );
  32. GLvoid  keyboard( GLubyte, GLint, GLint );
  33. GLvoid  drawScene( GLvoid );
  34.  
  35. void printHelp( char * );
  36.  
  37. /* Global Definitions */
  38.  
  39. #define KEY_ESC    27    /* ascii value for the escape key */
  40.  
  41. void
  42. main( int argc, char *argv[] )
  43. {
  44.     GLsizei width, height;
  45.  
  46.     glutInit( &argc, argv );
  47.  
  48.     width = glutGet( GLUT_SCREEN_WIDTH ); 
  49.     height = glutGet( GLUT_SCREEN_HEIGHT );
  50.     glutInitWindowPosition( (width / 2) + 2, height / 4 );
  51.     glutInitWindowSize( width / 2, height / 2 );
  52.     glutInitDisplayMode( GLUT_RGBA );
  53.     glutCreateWindow( argv[0] );
  54.  
  55.     initgfx();
  56.  
  57.     glutKeyboardFunc( keyboard );
  58.     glutDisplayFunc( drawScene ); 
  59.  
  60.     printHelp( argv[0] );
  61.  
  62.     gluPerspective( 45.0, (GLdouble) width/ (GLdouble)height, 3.0, 7.0 );
  63.  
  64.     /* Translate the origin between the near and far clipping planes. */
  65.     glTranslatef( 0.0, 0.0, -5.0 );
  66.  
  67.     glutMainLoop();
  68. }
  69.  
  70. void
  71. printHelp( char *progname )
  72. {
  73.     fprintf(stdout, 
  74.         "\n%s - render a rotated grid using a perspective projection\n\n"
  75.         "Escape Key        - exit the program\n\n",
  76.         progname);
  77. }
  78.  
  79. GLvoid
  80. initgfx( GLvoid )
  81. {
  82.     glClearColor( 0.0, 0.0, 1.0, 1.0 );
  83.     glShadeModel( GL_FLAT );
  84. }
  85.  
  86. GLvoid 
  87. keyboard( GLubyte key, GLint x, GLint y )
  88. {
  89.     switch (key) {
  90.     case KEY_ESC:    /* Exit when the Escape key is pressed */
  91.         exit(0);
  92.     }
  93. }
  94.  
  95. GLvoid
  96. drawScene( GLvoid )
  97. {
  98.     static GLfloat    whiteColor[] = { 1.0, 1.0, 1.0 };
  99.  
  100.     glClear( GL_COLOR_BUFFER_BIT );
  101.  
  102.     /* Rotate grid around the X axis - push the top of the grid
  103.      *    into the screen
  104.      */
  105.     glRotatef( -60.0, 1.0, 0.0, 0.0 );
  106.  
  107.     /* Draw grid centered around translated origin */
  108.     glColor3fv( whiteColor );    
  109.     WireGrid();
  110.  
  111.     glFlush();
  112. }
  113.