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 / answers / shape_b.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-11  |  1.9 KB  |  78 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. /* shape_b.c - open a window, clear the background, set up
  19.  *    our world, and draw 2 connected lines.
  20.  */
  21. #include <GL/gl.h>
  22. #include <GL/glu.h>
  23. #include <GL/glut.h>
  24.  
  25. /* Function Prototypes */
  26. GLvoid initgfx( GLvoid );
  27. GLvoid drawScene( GLvoid );
  28.  
  29. void
  30. main( int argc, char *argv[] )
  31. {
  32.     GLsizei width, height;
  33.  
  34.     glutInit( &argc, argv );
  35.  
  36.     width = glutGet( GLUT_SCREEN_WIDTH ); 
  37.     height = glutGet( GLUT_SCREEN_HEIGHT );
  38.     glutInitWindowPosition( width / 4, height / 4 );
  39.     glutInitWindowSize( width / 2, height / 2 );
  40.     glutInitDisplayMode( GLUT_RGBA );
  41.     glutCreateWindow( argv[0] );
  42.  
  43.     initgfx();
  44.  
  45.     glutDisplayFunc( drawScene ); 
  46.  
  47.     glutMainLoop();
  48. }
  49.  
  50. GLvoid
  51. initgfx( GLvoid )
  52. {
  53.     /* set the clear color to white */
  54.     glClearColor( 1.0, 1.0, 1.0, 1.0 );
  55.  
  56.     /* set up our world */
  57.     glOrtho( -2.0, 2.0, -2.0, 2.0, -1.0, 1.0 );
  58. }
  59.  
  60. GLvoid
  61. drawScene( GLvoid )
  62. {
  63.     glClear( GL_COLOR_BUFFER_BIT );
  64.  
  65.     /* We'll do all our OpenGL rendering here */
  66.  
  67.     /* Rendering Lab: shape (b) */
  68.     glColor3f( 0.0, 1.0, 0.0 );    /* green */
  69.     glBegin( GL_LINE_STRIP );
  70.         glVertex2f( -1.0, -1.0 );
  71.         glVertex2f( 0.0, 0.0 );
  72.         glVertex2f( 1.0, 0.0 );
  73.     glEnd();
  74.  
  75.     checkError( "drawScene" );
  76.     glFlush();
  77. }
  78.