Clone of mesa.
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.

font.c 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /*
  2. * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc.
  3. *
  4. * Permission to use, copy, modify, distribute, and sell this software and
  5. * its documentation for any purpose is hereby granted without fee, provided
  6. * that (i) the above copyright notices and this permission notice appear in
  7. * all copies of the software and related documentation, and (ii) the name of
  8. * Silicon Graphics may not be used in any advertising or
  9. * publicity relating to the software without the specific, prior written
  10. * permission of Silicon Graphics.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF
  13. * ANY KIND,
  14. * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
  15. * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  16. *
  17. * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR
  18. * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  19. * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  20. * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
  21. * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  22. * OF THIS SOFTWARE.
  23. */
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include <stdlib.h>
  27. #include <GL/glut.h>
  28. #define OPENGL_WIDTH 24
  29. #define OPENGL_HEIGHT 13
  30. char string[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz";
  31. GLenum rgb, doubleBuffer, windType;
  32. float angleX = 0.0, angleY = 0.0, angleZ = 0.0;
  33. float scaleX = 1.0, scaleY = 1.0, scaleZ = 1.0;
  34. float shiftX = 0.0, shiftY = 0.0, shiftZ = 0.0;
  35. #include "tkmap.c"
  36. static void DrawBitmapString(void *font, const char *string)
  37. {
  38. int i;
  39. for (i = 0; string[i]; i++)
  40. glutBitmapCharacter(font, string[i]);
  41. }
  42. static void DrawStrokeString(void *font, const char *string)
  43. {
  44. int i;
  45. for (i = 0; string[i]; i++)
  46. glutStrokeCharacter(font, string[i]);
  47. }
  48. static void Init(void)
  49. {
  50. glClearColor(0.0, 0.0, 0.0, 0.0);
  51. glClearIndex(0.0);
  52. }
  53. static void Reshape(int width, int height)
  54. {
  55. glViewport(0, 0, (GLint)width, (GLint)height);
  56. glMatrixMode(GL_PROJECTION);
  57. glLoadIdentity();
  58. glOrtho(-400.0, 400.0, -200.0, 200.0, -400.0, 400.0);
  59. glMatrixMode(GL_MODELVIEW);
  60. }
  61. static void Key2(int key, int x, int y)
  62. {
  63. switch (key) {
  64. case GLUT_KEY_LEFT:
  65. shiftX -= 20.0;
  66. break;
  67. case GLUT_KEY_RIGHT:
  68. shiftX += 20.0;
  69. break;
  70. case GLUT_KEY_UP:
  71. shiftY += 20.0;
  72. break;
  73. case GLUT_KEY_DOWN:
  74. shiftY -= 20.0;
  75. break;
  76. default:
  77. return;
  78. }
  79. glutPostRedisplay();
  80. }
  81. static void Key(unsigned char key, int x, int y)
  82. {
  83. switch (key) {
  84. case 27:
  85. exit(1);
  86. case 'n':
  87. shiftZ += 20.0;
  88. break;
  89. case 'm':
  90. shiftZ -= 20.0;
  91. break;
  92. case 'q':
  93. scaleX -= 0.1;
  94. if (scaleX < 0.1) {
  95. scaleX = 0.1;
  96. }
  97. break;
  98. case 'w':
  99. scaleX += 0.1;
  100. break;
  101. case 'a':
  102. scaleY -= 0.1;
  103. if (scaleY < 0.1) {
  104. scaleY = 0.1;
  105. }
  106. break;
  107. case 's':
  108. scaleY += 0.1;
  109. break;
  110. case 'z':
  111. scaleZ -= 0.1;
  112. if (scaleZ < 0.1) {
  113. scaleZ = 0.1;
  114. }
  115. break;
  116. case 'x':
  117. scaleZ += 0.1;
  118. break;
  119. case 'e':
  120. angleX -= 5.0;
  121. if (angleX < 0.0) {
  122. angleX = 360.0 + angleX;
  123. }
  124. break;
  125. case 'r':
  126. angleX += 5.0;
  127. if (angleX > 360.0) {
  128. angleX = angleX - 360.0;
  129. }
  130. break;
  131. case 'd':
  132. angleY -= 5.0;
  133. if (angleY < 0.0) {
  134. angleY = 360.0 + angleY;
  135. }
  136. break;
  137. case 'f':
  138. angleY += 5.0;
  139. if (angleY > 360.0) {
  140. angleY = angleY - 360.0;
  141. }
  142. break;
  143. case 'c':
  144. angleZ -= 5.0;
  145. if (angleZ < 0.0) {
  146. angleZ = 360.0 + angleZ;
  147. }
  148. break;
  149. case 'v':
  150. angleZ += 5.0;
  151. if (angleZ > 360.0) {
  152. angleZ = angleZ - 360.0;
  153. }
  154. break;
  155. default:
  156. return;
  157. }
  158. glutPostRedisplay();
  159. }
  160. static void Draw(void)
  161. {
  162. glClear(GL_COLOR_BUFFER_BIT);
  163. SetColor(COLOR_WHITE);
  164. glPushMatrix();
  165. glTranslatef(shiftX, shiftY, shiftZ);
  166. glRotatef(angleX, 1.0, 0.0, 0.0);
  167. glRotatef(angleY, 0.0, 1.0, 0.0);
  168. glRotatef(angleZ, 0.0, 0.0, 1.0);
  169. glScalef(scaleX, scaleY, scaleZ);
  170. glPushMatrix();
  171. glRasterPos2f(-390.5, 0.5);
  172. DrawBitmapString(GLUT_BITMAP_9_BY_15, string);
  173. glPopMatrix();
  174. glPushMatrix();
  175. glTranslatef(-390.5, -30.5, 0.0);
  176. DrawStrokeString(GLUT_STROKE_ROMAN, string);
  177. glPopMatrix();
  178. glPopMatrix();
  179. glFlush();
  180. if (doubleBuffer) {
  181. glutSwapBuffers();
  182. }
  183. }
  184. static GLenum Args(int argc, char **argv)
  185. {
  186. GLint i;
  187. rgb = GL_TRUE;
  188. doubleBuffer = GL_FALSE;
  189. for (i = 1; i < argc; i++) {
  190. if (strcmp(argv[i], "-ci") == 0) {
  191. rgb = GL_FALSE;
  192. } else if (strcmp(argv[i], "-rgb") == 0) {
  193. rgb = GL_TRUE;
  194. } else if (strcmp(argv[i], "-sb") == 0) {
  195. doubleBuffer = GL_FALSE;
  196. } else if (strcmp(argv[i], "-db") == 0) {
  197. doubleBuffer = GL_TRUE;
  198. } else {
  199. printf("%s (Bad option).\n", argv[i]);
  200. return GL_FALSE;
  201. }
  202. }
  203. return GL_TRUE;
  204. }
  205. int main(int argc, char **argv)
  206. {
  207. glutInit(&argc, argv);
  208. if (Args(argc, argv) == GL_FALSE) {
  209. exit(1);
  210. }
  211. glutInitWindowPosition(0, 0); glutInitWindowSize( 800, 400);
  212. windType = (rgb) ? GLUT_RGB : GLUT_INDEX;
  213. windType |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
  214. glutInitDisplayMode(windType);
  215. if (glutCreateWindow("Font Test") == GL_FALSE) {
  216. exit(1);
  217. }
  218. InitMap();
  219. Init();
  220. glutReshapeFunc(Reshape);
  221. glutKeyboardFunc(Key);
  222. glutSpecialFunc(Key2);
  223. glutDisplayFunc(Draw);
  224. glutMainLoop();
  225. return 0;
  226. }