Clone of mesa.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

stroke.c 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /* Copyright (c) Mark J. Kilgard, 1994. */
  2. /*
  3. * (c) Copyright 1993, Silicon Graphics, Inc.
  4. * ALL RIGHTS RESERVED
  5. * Permission to use, copy, modify, and distribute this software for
  6. * any purpose and without fee is hereby granted, provided that the above
  7. * copyright notice appear in all copies and that both the copyright notice
  8. * and this permission notice appear in supporting documentation, and that
  9. * the name of Silicon Graphics, Inc. not be used in advertising
  10. * or publicity pertaining to distribution of the software without specific,
  11. * written prior permission.
  12. *
  13. * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  14. * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  15. * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  16. * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
  17. * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  18. * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  19. * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  20. * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  21. * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
  22. * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  23. * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  24. * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  25. *
  26. * US Government Users Restricted Rights
  27. * Use, duplication, or disclosure by the Government is subject to
  28. * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  29. * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  30. * clause at DFARS 252.227-7013 and/or in similar or successor
  31. * clauses in the FAR or the DOD or NASA FAR Supplement.
  32. * Unpublished-- rights reserved under the copyright laws of the
  33. * United States. Contractor/manufacturer is Silicon Graphics,
  34. * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
  35. *
  36. * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  37. */
  38. /*
  39. * stroke.c
  40. * This program demonstrates some characters of a
  41. * stroke (vector) font. The characters are represented
  42. * by display lists, which are given numbers which
  43. * correspond to the ASCII values of the characters.
  44. * Use of glCallLists() is demonstrated.
  45. */
  46. #include <stdlib.h>
  47. #include <string.h>
  48. #include <GL/glut.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. for (;;) {
  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 = (GLsizei) 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. static void reshape(GLsizei w, GLsizei h)
  140. {
  141. glViewport(0, 0, w, h);
  142. glMatrixMode(GL_PROJECTION);
  143. glLoadIdentity();
  144. glOrtho(0.0, (GLdouble)w, 0.0, (GLdouble)h, -1.0, 1.0);
  145. glMatrixMode(GL_MODELVIEW);
  146. glLoadIdentity();
  147. }
  148. static void
  149. key(unsigned char k, int x, int y)
  150. {
  151. switch (k) {
  152. case 27: /* Escape */
  153. exit(0);
  154. break;
  155. default:
  156. return;
  157. }
  158. glutPostRedisplay();
  159. }
  160. /* Main Loop
  161. * Open window with initial window size, title bar,
  162. * RGBA display mode, and handle input events.
  163. */
  164. int main(int argc, char** argv)
  165. {
  166. glutInit(&argc, argv);
  167. glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
  168. glutInitWindowSize (440, 120);
  169. glutCreateWindow (argv[0]);
  170. myinit ();
  171. glutDisplayFunc(display);
  172. glutReshapeFunc(reshape);
  173. glutKeyboardFunc(key);
  174. glutMainLoop();
  175. return 0; /* ANSI C requires main to return int. */
  176. }