Windows NT 4.0 source code leak
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.

285 lines
6.5 KiB

4 years ago
  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. #include <stdio.h>
  38. #include <string.h>
  39. #include <stdlib.h>
  40. #include "tk.h"
  41. #define OPENGL_WIDTH 24
  42. #define OPENGL_HEIGHT 13
  43. char string[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz";
  44. GLenum rgb, doubleBuffer, directRender, windType;
  45. GLuint strokeBase, outlineBase, filledBase, bitmapBase;
  46. float angleX = 0.0, angleY = 0.0, angleZ = 0.0;
  47. float scaleX = 1.0, scaleY = 1.0, scaleZ = 1.0;
  48. float shiftX = 0.0, shiftY = 0.0, shiftZ = 0.0;
  49. static void Init(void)
  50. {
  51. strokeBase = glGenLists(256);
  52. if (tkCreateStrokeFont(strokeBase) == GL_FALSE) {
  53. tkQuit();
  54. }
  55. outlineBase = glGenLists(256);
  56. if (tkCreateOutlineFont(outlineBase) == GL_FALSE) {
  57. tkQuit();
  58. }
  59. filledBase = glGenLists(256);
  60. if (tkCreateFilledFont(filledBase) == GL_FALSE) {
  61. tkQuit();
  62. }
  63. bitmapBase = glGenLists(256);
  64. if (tkCreateBitmapFont(bitmapBase) == GL_FALSE) {
  65. tkQuit();
  66. }
  67. glClearColor(0.0, 0.0, 0.0, 0.0);
  68. glClearIndex(0.0);
  69. }
  70. static void Reshape(int width, int height)
  71. {
  72. glViewport(0, 0, (GLint)width, (GLint)height);
  73. glMatrixMode(GL_PROJECTION);
  74. glLoadIdentity();
  75. glOrtho(-400.0, 400.0, -200.0, 200.0, -400.0, 400.0);
  76. glMatrixMode(GL_MODELVIEW);
  77. }
  78. static GLenum Key(int key, GLenum mask)
  79. {
  80. switch (key) {
  81. case TK_ESCAPE:
  82. tkQuit();
  83. case TK_LEFT:
  84. shiftX -= 20.0;
  85. break;
  86. case TK_RIGHT:
  87. shiftX += 20.0;
  88. break;
  89. case TK_UP:
  90. shiftY += 20.0;
  91. break;
  92. case TK_DOWN:
  93. shiftY -= 20.0;
  94. break;
  95. case TK_n:
  96. shiftZ += 20.0;
  97. break;
  98. case TK_m:
  99. shiftZ -= 20.0;
  100. break;
  101. case TK_q:
  102. scaleX -= 0.1;
  103. if (scaleX < 0.1) {
  104. scaleX = 0.1;
  105. }
  106. break;
  107. case TK_w:
  108. scaleX += 0.1;
  109. break;
  110. case TK_a:
  111. scaleY -= 0.1;
  112. if (scaleY < 0.1) {
  113. scaleY = 0.1;
  114. }
  115. break;
  116. case TK_s:
  117. scaleY += 0.1;
  118. break;
  119. case TK_z:
  120. scaleZ -= 0.1;
  121. if (scaleZ < 0.1) {
  122. scaleZ = 0.1;
  123. }
  124. break;
  125. case TK_x:
  126. scaleZ += 0.1;
  127. break;
  128. case TK_e:
  129. angleX -= 5.0;
  130. if (angleX < 0.0) {
  131. angleX = 360.0 + angleX;
  132. }
  133. break;
  134. case TK_r:
  135. angleX += 5.0;
  136. if (angleX > 360.0) {
  137. angleX = angleX - 360.0;
  138. }
  139. break;
  140. case TK_d:
  141. angleY -= 5.0;
  142. if (angleY < 0.0) {
  143. angleY = 360.0 + angleY;
  144. }
  145. break;
  146. case TK_f:
  147. angleY += 5.0;
  148. if (angleY > 360.0) {
  149. angleY = angleY - 360.0;
  150. }
  151. break;
  152. case TK_c:
  153. angleZ -= 5.0;
  154. if (angleZ < 0.0) {
  155. angleZ = 360.0 + angleZ;
  156. }
  157. break;
  158. case TK_v:
  159. angleZ += 5.0;
  160. if (angleZ > 360.0) {
  161. angleZ = angleZ - 360.0;
  162. }
  163. break;
  164. default:
  165. return GL_FALSE;
  166. }
  167. return GL_TRUE;
  168. }
  169. static void Draw(void)
  170. {
  171. glClear(GL_COLOR_BUFFER_BIT);
  172. TK_SETCOLOR(windType, TK_WHITE);
  173. glPushMatrix();
  174. glTranslatef(shiftX, shiftY, shiftZ);
  175. glRotatef(angleX, 1.0, 0.0, 0.0);
  176. glRotatef(angleY, 0.0, 1.0, 0.0);
  177. glRotatef(angleZ, 0.0, 0.0, 1.0);
  178. glScalef(scaleX, scaleY, scaleZ);
  179. glPushMatrix();
  180. glRasterPos2f(-390.5, 0.5);
  181. tkDrawStr(bitmapBase, string);
  182. glPopMatrix();
  183. glPushMatrix();
  184. glTranslatef(-390.5, -30.5, 0.0);
  185. tkDrawStr(strokeBase, string);
  186. glPopMatrix();
  187. glPushMatrix();
  188. glTranslatef(-390.5, -60.5, 0.0);
  189. tkDrawStr(outlineBase, string);
  190. glPopMatrix();
  191. glPushMatrix();
  192. glTranslatef(-390.5, -90.5, 0.0);
  193. tkDrawStr(filledBase, string);
  194. glPopMatrix();
  195. glPopMatrix();
  196. glFlush();
  197. if (doubleBuffer) {
  198. tkSwapBuffers();
  199. }
  200. }
  201. static GLenum Args(int argc, char **argv)
  202. {
  203. GLint i;
  204. rgb = GL_TRUE;
  205. doubleBuffer = GL_FALSE;
  206. directRender = GL_FALSE;
  207. for (i = 1; i < argc; i++) {
  208. if (strcmp(argv[i], "-ci") == 0) {
  209. rgb = GL_FALSE;
  210. } else if (strcmp(argv[i], "-rgb") == 0) {
  211. rgb = GL_TRUE;
  212. } else if (strcmp(argv[i], "-sb") == 0) {
  213. doubleBuffer = GL_FALSE;
  214. } else if (strcmp(argv[i], "-db") == 0) {
  215. doubleBuffer = GL_TRUE;
  216. } else if (strcmp(argv[i], "-dr") == 0) {
  217. directRender = GL_TRUE;
  218. } else if (strcmp(argv[i], "-ir") == 0) {
  219. directRender = GL_FALSE;
  220. } else {
  221. printf("%s (Bad option).\n", argv[i]);
  222. return GL_FALSE;
  223. }
  224. }
  225. return GL_TRUE;
  226. }
  227. void main(int argc, char **argv)
  228. {
  229. if (Args(argc, argv) == GL_FALSE) {
  230. tkQuit();
  231. }
  232. tkInitPosition(0, 0, 800, 400);
  233. windType = (rgb) ? TK_RGB : TK_INDEX;
  234. windType |= (doubleBuffer) ? TK_DOUBLE : TK_SINGLE;
  235. windType |= (directRender) ? TK_DIRECT : TK_INDIRECT;
  236. tkInitDisplayMode(windType);
  237. if (tkInitWindow("Font Test") == GL_FALSE) {
  238. tkQuit();
  239. }
  240. Init();
  241. tkExposeFunc(Reshape);
  242. tkReshapeFunc(Reshape);
  243. tkKeyDownFunc(Key);
  244. tkDisplayFunc(Draw);
  245. tkExec();
  246. }