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.

344 lines
7.7 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 "windows.h"
  38. #include <stdio.h>
  39. #include <string.h>
  40. #include <stdlib.h>
  41. #include <math.h>
  42. #include <time.h>
  43. #include "GL/gl.h"
  44. #include "GL/glu.h"
  45. #include "tk.h"
  46. #define PI 3.141592657
  47. enum {
  48. NORMAL = 0,
  49. WEIRD = 1
  50. };
  51. enum {
  52. STREAK = 0,
  53. CIRCLE = 1
  54. };
  55. #define MAXSTARS 400
  56. #define MAXPOS 10000
  57. #define MAXWARP 10
  58. #define MAXANGLES 6000
  59. typedef struct _starRec {
  60. GLint type;
  61. float x[2], y[2], z[2];
  62. float offsetX, offsetY, offsetR, rotation;
  63. } starRec;
  64. GLenum doubleBuffer, directRender;
  65. GLint windW, windH;
  66. GLenum flag = NORMAL;
  67. GLint starCount = MAXSTARS / 2;
  68. float speed = 1.0;
  69. GLint nitro = 0;
  70. starRec stars[MAXSTARS];
  71. float sinTable[MAXANGLES];
  72. float Sin(float angle)
  73. {
  74. return (sinTable[(GLint)angle]);
  75. }
  76. float Cos(float angle)
  77. {
  78. return (sinTable[((GLint)angle+(MAXANGLES/4))%MAXANGLES]);
  79. }
  80. void NewStar(GLint n, GLint d)
  81. {
  82. if (rand()%4 == 0) {
  83. stars[n].type = CIRCLE;
  84. } else {
  85. stars[n].type = STREAK;
  86. }
  87. stars[n].x[0] = (float)(rand() % MAXPOS - MAXPOS / 2);
  88. stars[n].y[0] = (float)(rand() % MAXPOS - MAXPOS / 2);
  89. stars[n].z[0] = (float)(rand() % MAXPOS + d);
  90. if (rand()%4 == 0 && flag == WEIRD) {
  91. stars[n].offsetX = (float)(rand() % 100 - 100 / 2);
  92. stars[n].offsetY = (float)(rand() % 100 - 100 / 2);
  93. stars[n].offsetR = (float)(rand() % 25 - 25 / 2);
  94. } else {
  95. stars[n].offsetX = 0.0;
  96. stars[n].offsetY = 0.0;
  97. stars[n].offsetR = 0.0;
  98. }
  99. }
  100. void RotatePoint(float *x, float *y, float rotation)
  101. {
  102. float tmpX, tmpY;
  103. tmpX = *x * Cos(rotation) - *y * Sin(rotation);
  104. tmpY = *y * Cos(rotation) + *x * Sin(rotation);
  105. *x = tmpX;
  106. *y = tmpY;
  107. }
  108. void MoveStars(void)
  109. {
  110. float offset;
  111. GLint n;
  112. offset = speed * 60.0;
  113. for (n = 0; n < starCount; n++) {
  114. stars[n].x[1] = stars[n].x[0];
  115. stars[n].y[1] = stars[n].y[0];
  116. stars[n].z[1] = stars[n].z[0];
  117. stars[n].x[0] += stars[n].offsetX;
  118. stars[n].y[0] += stars[n].offsetY;
  119. stars[n].z[0] -= offset;
  120. stars[n].rotation += stars[n].offsetR;
  121. if (stars[n].rotation > MAXANGLES) {
  122. stars[n].rotation = 0.0;
  123. }
  124. }
  125. }
  126. GLenum StarPoint(GLint n)
  127. {
  128. float x0, y0, x1, y1, width;
  129. GLint i;
  130. x0 = stars[n].x[0] * windW / stars[n].z[0];
  131. y0 = stars[n].y[0] * windH / stars[n].z[0];
  132. RotatePoint(&x0, &y0, stars[n].rotation);
  133. x0 += windW / 2.0;
  134. y0 += windH / 2.0;
  135. if (x0 >= 0.0 && x0 < windW && y0 >= 0.0 && y0 < windH) {
  136. if (stars[n].type == STREAK) {
  137. x1 = stars[n].x[1] * windW / stars[n].z[1];
  138. y1 = stars[n].y[1] * windH / stars[n].z[1];
  139. RotatePoint(&x1, &y1, stars[n].rotation);
  140. x1 += windW / 2.0;
  141. y1 += windH / 2.0;
  142. glLineWidth(MAXPOS/100.0/stars[n].z[0]+1.0);
  143. glColor3f(1.0, (MAXWARP-speed)/MAXWARP, (MAXWARP-speed)/MAXWARP);
  144. if (fabs(x0-x1) < 1.0 && fabs(y0-y1) < 1.0) {
  145. glBegin(GL_POINTS);
  146. glVertex2f(x0, y0);
  147. glEnd();
  148. } else {
  149. glBegin(GL_LINES);
  150. glVertex2f(x0, y0);
  151. glVertex2f(x1, y1);
  152. glEnd();
  153. }
  154. } else {
  155. width = MAXPOS / 10.0 / stars[n].z[0] + 1.0;
  156. glColor3f(1.0, 0.0, 0.0);
  157. glBegin(GL_POLYGON);
  158. for (i = 0; i < 8; i++) {
  159. float x = x0 + width * Cos((float)i*MAXANGLES/8.0);
  160. float y = y0 + width * Sin((float)i*MAXANGLES/8.0);
  161. glVertex2f(x, y);
  162. };
  163. glEnd();
  164. }
  165. return GL_TRUE;
  166. } else {
  167. return GL_FALSE;
  168. }
  169. }
  170. void ShowStars(void)
  171. {
  172. GLint n;
  173. glClear(GL_COLOR_BUFFER_BIT);
  174. for (n = 0; n < starCount; n++) {
  175. if (stars[n].z[0] > speed || (stars[n].z[0] > 0.0 && speed < MAXWARP)) {
  176. if (StarPoint(n) == GL_FALSE) {
  177. NewStar(n, MAXPOS);
  178. }
  179. } else {
  180. NewStar(n, MAXPOS);
  181. }
  182. }
  183. }
  184. static void Init(void)
  185. {
  186. float angle;
  187. GLint n;
  188. srand((unsigned int)time(NULL));
  189. for (n = 0; n < MAXSTARS; n++) {
  190. NewStar(n, 100);
  191. }
  192. angle = 0.0;
  193. for (n = 0; n < MAXANGLES ; n++) {
  194. sinTable[n] = sin(angle);
  195. angle += PI / (MAXANGLES / 2.0);
  196. }
  197. glClearColor(0.0, 0.0, 0.0, 0.0);
  198. glDisable(GL_DITHER);
  199. }
  200. void Reshape(int width, int height)
  201. {
  202. windW = (GLint)width;
  203. windH = (GLint)height;
  204. glViewport(0, 0, windW, windH);
  205. glMatrixMode(GL_PROJECTION);
  206. glLoadIdentity();
  207. gluOrtho2D(-0.5, windW+0.5, -0.5, windH+0.5);
  208. glMatrixMode(GL_MODELVIEW);
  209. }
  210. static GLenum Key(int key, GLenum mask)
  211. {
  212. switch (key) {
  213. case TK_ESCAPE:
  214. tkQuit();
  215. case TK_SPACE:
  216. flag = (flag == NORMAL) ? WEIRD : NORMAL;
  217. break;
  218. case TK_t:
  219. nitro = 1;
  220. break;
  221. default:
  222. return GL_FALSE;
  223. }
  224. return GL_TRUE;
  225. }
  226. void Idle(void)
  227. {
  228. MoveStars();
  229. ShowStars();
  230. if (nitro > 0) {
  231. speed = (float)(nitro / 10) + 1.0;
  232. if (speed > MAXWARP) {
  233. speed = MAXWARP;
  234. }
  235. if (++nitro > MAXWARP*10) {
  236. nitro = -nitro;
  237. }
  238. } else if (nitro < 0) {
  239. nitro++;
  240. speed = (float)(-nitro / 10) + 1.0;
  241. if (speed > MAXWARP) {
  242. speed = MAXWARP;
  243. }
  244. }
  245. glFlush();
  246. if (doubleBuffer) {
  247. tkSwapBuffers();
  248. }
  249. }
  250. static GLenum Args(int argc, char **argv)
  251. {
  252. GLint i;
  253. doubleBuffer = GL_FALSE;
  254. directRender = GL_FALSE;
  255. for (i = 1; i < argc; i++) {
  256. if (strcmp(argv[i], "-sb") == 0) {
  257. doubleBuffer = GL_FALSE;
  258. } else if (strcmp(argv[i], "-db") == 0) {
  259. doubleBuffer = GL_TRUE;
  260. } else if (strcmp(argv[i], "-dr") == 0) {
  261. directRender = GL_TRUE;
  262. } else if (strcmp(argv[i], "-ir") == 0) {
  263. directRender = GL_FALSE;
  264. }
  265. }
  266. return GL_TRUE;
  267. }
  268. void main(int argc, char **argv)
  269. {
  270. GLenum type;
  271. if (Args(argc, argv) == GL_FALSE) {
  272. tkQuit();
  273. }
  274. windW = 300;
  275. windH = 300;
  276. tkInitPosition(0, 0, 300, 300);
  277. type = TK_RGB;
  278. type |= (doubleBuffer) ? TK_DOUBLE : TK_SINGLE;
  279. type |= (directRender) ? TK_DIRECT : TK_INDIRECT;
  280. tkInitDisplayMode(type);
  281. if (tkInitWindow("Stars") == GL_FALSE) {
  282. tkQuit();
  283. }
  284. Init();
  285. tkExposeFunc(Reshape);
  286. tkReshapeFunc(Reshape);
  287. tkKeyDownFunc(Key);
  288. tkIdleFunc(Idle);
  289. tkExec();
  290. }