Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

165 lines
4.9 KiB

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