home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / opengl / auxdemo / stroke.c < prev    next >
C/C++ Source or Header  |  1999-05-11  |  5KB  |  166 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 <string.h>
  46. #include <GL/gl.h>
  47. #include <GL/glu.h>
  48. #include "aux.h"
  49.  
  50. #define PT 1
  51. #define STROKE 2
  52. #define END 3
  53.  
  54. typedef struct charpoint {
  55.     GLfloat   x, y;
  56.     int    type;
  57. } CP;
  58.  
  59. CP Adata[] = {
  60.     { 0, 0, PT}, {0, 9, PT}, {1, 10, PT}, {4, 10, PT}, 
  61.     {5, 9, PT}, {5, 0, STROKE}, {0, 5, PT}, {5, 5, END}
  62. };
  63.  
  64. CP Edata[] = {
  65.     {5, 0, PT}, {0, 0, PT}, {0, 10, PT}, {5, 10, STROKE},
  66.     {0, 5, PT}, {4, 5, END}
  67. };
  68.  
  69. CP Pdata[] = {
  70.     {0, 0, PT}, {0, 10, PT},  {4, 10, PT}, {5, 9, PT}, {5, 6, PT}, 
  71.     {4, 5, PT}, {0, 5, END}
  72. };
  73.  
  74. CP Rdata[] = {
  75.     {0, 0, PT}, {0, 10, PT},  {4, 10, PT}, {5, 9, PT}, {5, 6, PT}, 
  76.     {4, 5, PT}, {0, 5, STROKE}, {3, 5, PT}, {5, 0, END}
  77. };
  78.  
  79. CP Sdata[] = {
  80.     {0, 1, PT}, {1, 0, PT}, {4, 0, PT}, {5, 1, PT}, {5, 4, PT}, 
  81.     {4, 5, PT}, {1, 5, PT}, {0, 6, PT}, {0, 9, PT}, {1, 10, PT}, 
  82.     {4, 10, PT}, {5, 9, END}
  83. };
  84.  
  85. /*  drawLetter() interprets the instructions from the array
  86.  *  for that letter and renders the letter with line segments.
  87.  */
  88. void drawLetter(CP *l)
  89. {
  90.     glBegin(GL_LINE_STRIP);
  91.     while (1) {
  92.     switch (l->type) {
  93.         case PT:
  94.         glVertex2fv(&l->x);
  95.         break;
  96.         case STROKE:
  97.         glVertex2fv(&l->x);
  98.         glEnd();
  99.         glBegin(GL_LINE_STRIP);
  100.         break;
  101.         case END:
  102.         glVertex2fv(&l->x);
  103.         glEnd();
  104.         glTranslatef(8.0, 0.0, 0.0);
  105.         return;
  106.     }
  107.     l++;
  108.     }
  109. }
  110.  
  111. /*  Create a display list for each of 6 characters    */
  112. void myinit (void)
  113. {
  114.     GLuint base;
  115.  
  116.     glShadeModel (GL_FLAT);
  117.  
  118.     base = glGenLists (128);
  119.     glListBase(base);
  120.     glNewList(base+'A', GL_COMPILE); drawLetter(Adata); glEndList();
  121.     glNewList(base+'E', GL_COMPILE); drawLetter(Edata); glEndList();
  122.     glNewList(base+'P', GL_COMPILE); drawLetter(Pdata); glEndList();
  123.     glNewList(base+'R', GL_COMPILE); drawLetter(Rdata); glEndList();
  124.     glNewList(base+'S', GL_COMPILE); drawLetter(Sdata); glEndList();
  125.     glNewList(base+' ', GL_COMPILE); glTranslatef(8.0, 0.0, 0.0); glEndList();
  126. }
  127.  
  128. char *test1 = "A SPARE SERAPE APPEARS AS";
  129. char *test2 = "APES PREPARE RARE PEPPERS";
  130.  
  131. void printStrokedString(char *s)
  132. {
  133.     GLsizei len = strlen(s);
  134.     glCallLists(len, GL_BYTE, (GLbyte *)s);
  135. }
  136.  
  137. void display(void)
  138. {
  139.     glClear(GL_COLOR_BUFFER_BIT);
  140.     glColor3f(1.0, 1.0, 1.0);
  141.     glPushMatrix();
  142.     glScalef(2.0, 2.0, 2.0);
  143.     glTranslatef(10.0, 30.0, 0.0);
  144.     printStrokedString(test1);
  145.     glPopMatrix();
  146.     glPushMatrix();
  147.     glScalef(2.0, 2.0, 2.0);
  148.     glTranslatef(10.0, 13.0, 0.0);
  149.     printStrokedString(test2);
  150.     glPopMatrix();
  151.     glFlush();
  152. }
  153.  
  154. /*  Main Loop
  155.  *  Open window with initial window size, title bar, 
  156.  *  RGBA display mode, and handle input events.
  157.  */
  158. int main(int argc, char** argv)
  159. {
  160.     auxInitDisplayMode (AUX_SINGLE | AUX_RGB);
  161.     auxInitPosition (0, 0, 440, 120);
  162.     auxInitWindow (argv[0]);
  163.     myinit ();
  164.     auxMainLoop(display);
  165. }
  166.