home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / tutorials / custEducation / opengl2 / examples / irisgl_vs_opengl / lineStipple.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-11  |  3.2 KB  |  148 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. /* lineStipple.c  - open a window, clear the background, 
  19.  *    and render some lines each with different stippling.
  20.  *
  21.  *    Escape key    - exit the program
  22.  */
  23. #include <GL/gl.h>
  24. #include <GL/glu.h>
  25. #include <GL/glut.h>
  26.  
  27. #include <math.h>
  28. #include <stdio.h>
  29.  
  30. /* Function Prototypes */
  31.  
  32. GLvoid  initgfx( GLvoid );
  33. GLvoid  drawScene( GLvoid );
  34. GLvoid  reshape( GLsizei, GLsizei );
  35. GLvoid  keyboard( GLubyte, GLint, GLint );
  36.  
  37. void printHelp( char * );
  38.  
  39. /* Global Definitions */
  40.  
  41. #define KEY_ESC    27    /* ascii value for the escape key */
  42.  
  43. void
  44. main( int argc, char *argv[] )
  45. {
  46.     GLsizei     width, height;
  47.  
  48.     glutInit( &argc, argv );
  49.  
  50.     width = glutGet( GLUT_SCREEN_WIDTH ); 
  51.     height = glutGet( GLUT_SCREEN_HEIGHT );
  52.     glutInitWindowPosition( width/4, height/4 ); 
  53.     glutInitWindowSize( width/2, height/2 );
  54.     glutInitDisplayMode( GLUT_RGBA );
  55.     glutCreateWindow( argv[0] );
  56.     
  57.     initgfx();
  58.  
  59.     glutKeyboardFunc( keyboard );
  60.     glutReshapeFunc( reshape );
  61.     glutDisplayFunc( drawScene ); 
  62.  
  63.     printHelp( argv[0] );
  64.  
  65.     glutMainLoop();
  66. }
  67.  
  68. GLvoid
  69. printHelp( char *progname )
  70. {
  71.     fprintf(stdout, "\n%s - demonstrates line stippling\n\n"
  72.         "Escape key        - exit the program\n\n",
  73.         progname
  74.     );
  75. }
  76.  
  77. GLvoid
  78. initgfx( GLvoid )
  79. {
  80.     glClearColor( 0.0, 0.0, 0.0, 1.0 );
  81.     glLineWidth( 3.5 );
  82. }
  83.  
  84. GLvoid 
  85. keyboard( GLubyte key, GLint x, GLint y )
  86. {
  87.     switch (key) {
  88.     case KEY_ESC:    /* Exit whenever the Escape key is pressed */
  89.         exit(0);
  90.     }
  91. }
  92.  
  93. GLvoid
  94. reshape( GLsizei width, GLsizei height )
  95. {
  96.     GLdouble    aspect;
  97.  
  98.     glViewport( 0, 0, width, height );
  99.  
  100.     aspect = (GLdouble) width / (GLdouble) height;
  101.  
  102.     glMatrixMode( GL_PROJECTION );
  103.     glLoadIdentity();
  104.         glOrtho( 0.0, 1.0, 0.0, 1.0, -1.0, 1.0 );
  105.     glMatrixMode( GL_MODELVIEW );
  106.     glLoadIdentity();
  107. }
  108.  
  109. GLvoid
  110. drawScene( GLvoid )
  111. {
  112.     glClear( GL_COLOR_BUFFER_BIT );
  113.  
  114.     /* Draw lines each with a different stipple factor */
  115.     glColor3f( 1.0, 1.0, 0.0 );
  116.     glBegin( GL_LINE_STRIP );
  117.         glVertex2f( 0.1, 0.1 );
  118.         glVertex2f( 0.5, 0.1 );
  119.         glVertex2f( 0.9, 0.2 );
  120.     glEnd();
  121.  
  122.     glEnable( GL_LINE_STIPPLE );
  123.  
  124.     glLineStipple( 1, 0x8888 );
  125.     glBegin( GL_LINE_STRIP );
  126.         glVertex2f( 0.1, 0.3 );
  127.         glVertex2f( 0.5, 0.3 );
  128.         glVertex2f( 0.9, 0.4 );
  129.     glEnd();
  130.  
  131.     glLineStipple( 2, 0x8888 );
  132.     glBegin( GL_LINE_LOOP );
  133.         glVertex2f( 0.1, 0.5 );
  134.         glVertex2f( 0.5, 0.5 );
  135.         glVertex2f( 0.9, 0.6 );
  136.     glEnd();
  137.  
  138.     glLineStipple( 3, 0x8888 );
  139.     glBegin( GL_LINE_LOOP );
  140.         glVertex2f( 0.1, 0.7 );
  141.         glVertex2f( 0.5, 0.7 );
  142.         glVertex2f( 0.9, 0.8 );
  143.     glEnd();
  144.  
  145.     glDisable( GL_LINE_STIPPLE );
  146.     glFlush();
  147. }
  148.