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 / orthoRotate.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-11  |  2.3 KB  |  108 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. /* orthoRotate.c - rotate the line grid around the X axis, making
  19.  *       it an object in '3D'.
  20.  *
  21.  *    Escape Key        - exit program
  22.  */
  23. #include <GL/gl.h>
  24. #include <GL/glut.h>
  25.  
  26. #include <stdio.h>
  27.  
  28. /*  Function Prototypes  */
  29.  
  30. GLvoid  initgfx( GLvoid );
  31. GLvoid  keyboard( GLubyte, GLint, GLint );
  32. GLvoid  drawScene( GLvoid );
  33.  
  34. void printHelp( char * );
  35.  
  36. /* Global Definitions */
  37.  
  38. #define KEY_ESC    27    /* ascii value for the escape key */
  39.  
  40. void
  41. main( int argc, char *argv[] )
  42. {
  43.     GLsizei width, height;
  44.  
  45.     glutInit( &argc, argv );
  46.  
  47.     width = glutGet( GLUT_SCREEN_WIDTH ); 
  48.     height = glutGet( GLUT_SCREEN_HEIGHT );
  49.     glutInitWindowPosition( 0, height / 4 );
  50.     glutInitWindowSize( width / 2, height / 2 );
  51.     glutInitDisplayMode( GLUT_RGBA );
  52.     glutCreateWindow( argv[0] );
  53.  
  54.     initgfx();
  55.  
  56.     glutKeyboardFunc( keyboard );
  57.     glutDisplayFunc( drawScene ); 
  58.  
  59.     printHelp( argv[0] );
  60.  
  61.     glOrtho( -2.0, 2.0, -2.0, 2.0, -1.0, 1.0 );
  62.  
  63.     glutMainLoop();
  64. }
  65.  
  66. void
  67. printHelp( char *progname )
  68. {
  69.     fprintf(stdout, 
  70.         "\n%s - render a rotated grid using an orthographic projection\n\n"
  71.         "Escape Key        - exit the program\n\n",
  72.         progname);
  73. }
  74.  
  75. GLvoid
  76. initgfx( GLvoid )
  77. {
  78.     glClearColor( 0.0, 0.0, 1.0, 1.0 );
  79.     glShadeModel( GL_FLAT );
  80. }
  81.  
  82. GLvoid 
  83. keyboard( GLubyte key, GLint x, GLint y )
  84. {
  85.     switch (key) {
  86.     case KEY_ESC:    /* Exit when the Escape key is pressed */
  87.         exit(0);
  88.     }
  89. }
  90.  
  91. GLvoid
  92. drawScene( GLvoid )
  93. {
  94.     static GLfloat    whiteColor[] = { 1.0, 1.0, 1.0 };
  95.  
  96.     glClear( GL_COLOR_BUFFER_BIT );
  97.  
  98.     /* Rotate grid around the X axis - push the top of the grid
  99.      *    into the screen
  100.      */
  101.     glRotatef( -60.0, 1.0, 0.0, 0.0 );
  102.  
  103.     glColor3fv( whiteColor );    
  104.     WireGrid();
  105.  
  106.     glFlush();
  107. }
  108.