home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / newopg.zip / STROKE.C < prev    next >
Text File  |  1995-03-04  |  5KB  |  165 lines

  1. /*
  2.  * (c) Copyright 1993, Silicon Graphics, Inc.
  3.  * ALL RIGHTS RESERVED 
  4.  * Permission to use, copy, modify, and distribute this software for 
  5.  * any purpose and without fee is hereby granted, provided that the above
  6.  * copyright notice appear in all copies and that both the copyright notice
  7.  * and this permission notice appear in supporting documentation, and that 
  8.  * the name of Silicon Graphics, Inc. not be used in advertising
  9.  * or publicity pertaining to distribution of the software without specific,
  10.  * written prior permission. 
  11.  *
  12.  * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  13.  * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  14.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  15.  * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
  16.  * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  17.  * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  18.  * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  19.  * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  20.  * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
  21.  * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  22.  * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  23.  * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  24.  * 
  25.  * US Government Users Restricted Rights 
  26.  * Use, duplication, or disclosure by the Government is subject to
  27.  * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  28.  * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  29.  * clause at DFARS 252.227-7013 and/or in similar or successor
  30.  * clauses in the FAR or the DOD or NASA FAR Supplement.
  31.  * Unpublished-- rights reserved under the copyright laws of the
  32.  * United States.  Contractor/manufacturer is Silicon Graphics,
  33.  * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
  34.  *
  35.  * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  36.  */
  37. /*
  38.  *  stroke.c 
  39.  *  This program demonstrates some characters of a 
  40.  *  stroke (vector) font.  The characters are represented
  41.  *  by display lists, which are given numbers which 
  42.  *  correspond to the ASCII values of the characters.
  43.  *  Use of glCallLists() is demonstrated.
  44.  */
  45. #include <GL/gl.h>
  46. #include <GL/glu.h>
  47. #include "aux.h"
  48.  
  49. #define PT 1
  50. #define STROKE 2
  51. #define END 3
  52.  
  53. typedef struct charpoint {
  54.     GLfloat   x, y;
  55.     int    type;
  56. } CP;
  57.  
  58. CP Adata[] = {
  59.     { 0, 0, PT}, {0, 9, PT}, {1, 10, PT}, {4, 10, PT}, 
  60.     {5, 9, PT}, {5, 0, STROKE}, {0, 5, PT}, {5, 5, END}
  61. };
  62.  
  63. CP Edata[] = {
  64.     {5, 0, PT}, {0, 0, PT}, {0, 10, PT}, {5, 10, STROKE},
  65.     {0, 5, PT}, {4, 5, END}
  66. };
  67.  
  68. CP Pdata[] = {
  69.     {0, 0, PT}, {0, 10, PT},  {4, 10, PT}, {5, 9, PT}, {5, 6, PT}, 
  70.     {4, 5, PT}, {0, 5, END}
  71. };
  72.  
  73. CP Rdata[] = {
  74.     {0, 0, PT}, {0, 10, PT},  {4, 10, PT}, {5, 9, PT}, {5, 6, PT}, 
  75.     {4, 5, PT}, {0, 5, STROKE}, {3, 5, PT}, {5, 0, END}
  76. };
  77.  
  78. CP Sdata[] = {
  79.     {0, 1, PT}, {1, 0, PT}, {4, 0, PT}, {5, 1, PT}, {5, 4, PT}, 
  80.     {4, 5, PT}, {1, 5, PT}, {0, 6, PT}, {0, 9, PT}, {1, 10, PT}, 
  81.     {4, 10, PT}, {5, 9, END}
  82. };
  83.  
  84. /*  drawLetter() interprets the instructions from the array
  85.  *  for that letter and renders the letter with line segments.
  86.  */
  87. void drawLetter(CP *l)
  88. {
  89.     glBegin(GL_LINE_STRIP);
  90.     while (1) {
  91.     switch (l->type) {
  92.         case PT:
  93.         glVertex2fv(&l->x);
  94.         break;
  95.         case STROKE:
  96.         glVertex2fv(&l->x);
  97.         glEnd();
  98.         glBegin(GL_LINE_STRIP);
  99.         break;
  100.         case END:
  101.         glVertex2fv(&l->x);
  102.         glEnd();
  103.         glTranslatef(8.0, 0.0, 0.0);
  104.         return;
  105.     }
  106.     l++;
  107.     }
  108. }
  109.  
  110. /*  Create a display list for each of 6 characters    */
  111. void myinit (void)
  112. {
  113.     GLuint base;
  114.  
  115.     glShadeModel (GL_FLAT);
  116.  
  117.     base = glGenLists (128);
  118.     glListBase(base);
  119.     glNewList(base+'A', GL_COMPILE); drawLetter(Adata); glEndList();
  120.     glNewList(base+'E', GL_COMPILE); drawLetter(Edata); glEndList();
  121.     glNewList(base+'P', GL_COMPILE); drawLetter(Pdata); glEndList();
  122.     glNewList(base+'R', GL_COMPILE); drawLetter(Rdata); glEndList();
  123.     glNewList(base+'S', GL_COMPILE); drawLetter(Sdata); glEndList();
  124.     glNewList(base+' ', GL_COMPILE); glTranslatef(8.0, 0.0, 0.0); glEndList();
  125. }
  126.  
  127. char *test1 = "A SPARE SERAPE APPEARS AS";
  128. char *test2 = "APES PREPARE RARE PEPPERS";
  129.  
  130. void printStrokedString(char *s)
  131. {
  132.     GLsizei len = strlen(s);
  133.     glCallLists(len, GL_BYTE, (GLbyte *)s);
  134. }
  135.  
  136. void display(void)
  137. {
  138.     glClear(GL_COLOR_BUFFER_BIT);
  139.     glColor3f(1.0, 1.0, 1.0);
  140.     glPushMatrix();
  141.     glScalef(2.0, 2.0, 2.0);
  142.     glTranslatef(10.0, 30.0, 0.0);
  143.     printStrokedString(test1);
  144.     glPopMatrix();
  145.     glPushMatrix();
  146.     glScalef(2.0, 2.0, 2.0);
  147.     glTranslatef(10.0, 13.0, 0.0);
  148.     printStrokedString(test2);
  149.     glPopMatrix();
  150.     glFlush();
  151. }
  152.  
  153. /*  Main Loop
  154.  *  Open window with initial window size, title bar, 
  155.  *  RGBA display mode, and handle input events.
  156.  */
  157. int main(int argc, char** argv)
  158. {
  159.     auxInitDisplayMode (AUX_SINGLE | AUX_RGB);
  160.     auxInitPosition (0, 0, 440, 120);
  161.     auxInitWindow (argv[0]);
  162.     myinit ();
  163.     auxMainLoop(display);
  164. }
  165.