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.

360 lines
7.2 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 <stdlib.h>
  40. #include <string.h>
  41. #include <GL/gl.h>
  42. #include <GL/glu.h>
  43. #include <math.h>
  44. #include "tk.h"
  45. #define INREAL float
  46. #define S_NUMPOINTS 13
  47. #define S_ORDER 3
  48. #define S_NUMKNOTS (S_NUMPOINTS + S_ORDER)
  49. #define T_NUMPOINTS 3
  50. #define T_ORDER 3
  51. #define T_NUMKNOTS (T_NUMPOINTS + T_ORDER)
  52. #define SQRT_TWO 1.41421356237309504880
  53. typedef INREAL Point[4];
  54. GLenum doubleBuffer, directRender;
  55. GLenum expectedError;
  56. GLint rotX = 40, rotY = 40;
  57. INREAL sknots[S_NUMKNOTS] = {
  58. -1.0, -1.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0,
  59. 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 9.0, 9.0
  60. };
  61. INREAL tknots[T_NUMKNOTS] = {
  62. 1.0, 1.0, 1.0, 2.0, 2.0, 2.0
  63. };
  64. Point ctlpoints[S_NUMPOINTS][T_NUMPOINTS] = {
  65. {
  66. {
  67. 4.0, 2.0, 2.0, 1.0
  68. },
  69. {
  70. 4.0, 1.6, 2.5, 1.0
  71. },
  72. {
  73. 4.0, 2.0, 3.0, 1.0
  74. }
  75. },
  76. {
  77. {
  78. 5.0, 4.0, 2.0, 1.0
  79. },
  80. {
  81. 5.0, 4.0, 2.5, 1.0
  82. },
  83. {
  84. 5.0, 4.0, 3.0, 1.0
  85. }
  86. },
  87. {
  88. {
  89. 6.0, 5.0, 2.0, 1.0
  90. },
  91. {
  92. 6.0, 5.0, 2.5, 1.0
  93. },
  94. {
  95. 6.0, 5.0, 3.0, 1.0
  96. }
  97. },
  98. {
  99. {
  100. SQRT_TWO*6.0, SQRT_TWO*6.0, SQRT_TWO*2.0, SQRT_TWO
  101. },
  102. {
  103. SQRT_TWO*6.0, SQRT_TWO*6.0, SQRT_TWO*2.5, SQRT_TWO
  104. },
  105. {
  106. SQRT_TWO*6.0, SQRT_TWO*6.0, SQRT_TWO*3.0, SQRT_TWO
  107. }
  108. },
  109. {
  110. {
  111. 5.2, 6.7, 2.0, 1.0
  112. },
  113. {
  114. 5.2, 6.7, 2.5, 1.0
  115. },
  116. {
  117. 5.2, 6.7, 3.0, 1.0
  118. }
  119. },
  120. {
  121. {
  122. SQRT_TWO*4.0, SQRT_TWO*6.0, SQRT_TWO*2.0, SQRT_TWO
  123. },
  124. {
  125. SQRT_TWO*4.0, SQRT_TWO*6.0, SQRT_TWO*2.5, SQRT_TWO
  126. },
  127. {
  128. SQRT_TWO*4.0, SQRT_TWO*6.0, SQRT_TWO*3.0, SQRT_TWO
  129. }
  130. },
  131. {
  132. {
  133. 4.0, 5.2, 2.0, 1.0
  134. },
  135. {
  136. 4.0, 4.6, 2.5, 1.0
  137. },
  138. {
  139. 4.0, 5.2, 3.0, 1.0
  140. }
  141. },
  142. {
  143. {
  144. SQRT_TWO*4.0, SQRT_TWO*6.0, SQRT_TWO*2.0, SQRT_TWO
  145. },
  146. {
  147. SQRT_TWO*4.0, SQRT_TWO*6.0, SQRT_TWO*2.5, SQRT_TWO
  148. },
  149. {
  150. SQRT_TWO*4.0, SQRT_TWO*6.0, SQRT_TWO*3.0, SQRT_TWO
  151. }
  152. },
  153. {
  154. {
  155. 2.8, 6.7, 2.0, 1.0
  156. },
  157. {
  158. 2.8, 6.7, 2.5, 1.0
  159. },
  160. {
  161. 2.8, 6.7, 3.0, 1.0
  162. }
  163. },
  164. {
  165. {
  166. SQRT_TWO*2.0, SQRT_TWO*6.0, SQRT_TWO*2.0, SQRT_TWO
  167. },
  168. {
  169. SQRT_TWO*2.0, SQRT_TWO*6.0, SQRT_TWO*2.5, SQRT_TWO
  170. },
  171. {
  172. SQRT_TWO*2.0, SQRT_TWO*6.0, SQRT_TWO*3.0, SQRT_TWO
  173. }
  174. },
  175. {
  176. {
  177. 2.0, 5.0, 2.0, 1.0
  178. },
  179. {
  180. 2.0, 5.0, 2.5, 1.0
  181. },
  182. {
  183. 2.0, 5.0, 3.0, 1.0
  184. }
  185. },
  186. {
  187. {
  188. 3.0, 4.0, 2.0, 1.0
  189. },
  190. {
  191. 3.0, 4.0, 2.5, 1.0
  192. },
  193. {
  194. 3.0, 4.0, 3.0, 1.0
  195. }
  196. },
  197. {
  198. {
  199. 4.0, 2.0, 2.0, 1.0
  200. },
  201. {
  202. 4.0, 1.6, 2.5, 1.0
  203. },
  204. {
  205. 4.0, 2.0, 3.0, 1.0
  206. }
  207. }
  208. };
  209. GLUnurbsObj *theNurbs;
  210. static void ErrorCallback(GLenum which)
  211. {
  212. if (which != expectedError) {
  213. fprintf(stderr, "Unexpected error occured (%d):\n", which);
  214. fprintf(stderr, " %s\n", gluErrorString(which));
  215. }
  216. }
  217. static void Init(void)
  218. {
  219. theNurbs = gluNewNurbsRenderer();
  220. gluNurbsCallback(theNurbs, GLU_ERROR, ErrorCallback);
  221. gluNurbsProperty(theNurbs, GLU_SAMPLING_TOLERANCE, 15.0);
  222. gluNurbsProperty(theNurbs, GLU_DISPLAY_MODE, GLU_OUTLINE_PATCH);
  223. expectedError = GLU_INVALID_ENUM;
  224. gluNurbsProperty(theNurbs, ~0, 15.0);
  225. expectedError = GLU_NURBS_ERROR13;
  226. gluEndSurface(theNurbs);
  227. expectedError = 0;
  228. glColor3f(1.0, 1.0, 1.0);
  229. }
  230. static void Reshape(int width, int height)
  231. {
  232. glViewport(0, 0, (GLint)width, (GLint)height);
  233. glMatrixMode(GL_PROJECTION);
  234. glLoadIdentity();
  235. glFrustum(-2.0, 2.0, -2.0, 2.0, 0.8, 10.0);
  236. gluLookAt(7.0, 4.5, 4.0, 4.5, 4.5, 2.5, 6.0, -3.0, 2.0);
  237. glMatrixMode(GL_MODELVIEW);
  238. }
  239. static GLenum Key(int key, GLenum mask)
  240. {
  241. switch (key) {
  242. case TK_ESCAPE:
  243. tkQuit();
  244. case TK_DOWN:
  245. rotX -= 5;
  246. break;
  247. case TK_UP:
  248. rotX += 5;
  249. break;
  250. case TK_LEFT:
  251. rotY -= 5;
  252. break;
  253. case TK_RIGHT:
  254. rotY += 5;
  255. break;
  256. default:
  257. return GL_FALSE;
  258. }
  259. return GL_TRUE;
  260. }
  261. static void Draw(void)
  262. {
  263. glClear(GL_COLOR_BUFFER_BIT);
  264. glPushMatrix();
  265. glTranslatef(4.0, 4.5, 2.5);
  266. glRotatef(rotY, 1, 0, 0);
  267. glRotatef(rotX, 0, 1, 0);
  268. glTranslatef(-4.0, -4.5, -2.5);
  269. gluBeginSurface(theNurbs);
  270. gluNurbsSurface(theNurbs, S_NUMKNOTS, sknots, T_NUMKNOTS, tknots,
  271. 4*T_NUMPOINTS, 4, &ctlpoints[0][0][0], S_ORDER,
  272. T_ORDER, GL_MAP2_VERTEX_4);
  273. gluEndSurface(theNurbs);
  274. glPopMatrix();
  275. glFlush();
  276. if (doubleBuffer) {
  277. tkSwapBuffers();
  278. }
  279. }
  280. static GLenum Args(int argc, char **argv)
  281. {
  282. GLint i;
  283. doubleBuffer = GL_FALSE;
  284. directRender = GL_FALSE;
  285. for (i = 1; i < argc; i++) {
  286. if (strcmp(argv[i], "-sb") == 0) {
  287. doubleBuffer = GL_FALSE;
  288. } else if (strcmp(argv[i], "-db") == 0) {
  289. doubleBuffer = GL_TRUE;
  290. } else if (strcmp(argv[i], "-dr") == 0) {
  291. directRender = GL_TRUE;
  292. } else if (strcmp(argv[i], "-ir") == 0) {
  293. directRender = GL_FALSE;
  294. } else {
  295. printf("%s (Bad option).\n", argv[i]);
  296. return GL_FALSE;
  297. }
  298. }
  299. return GL_TRUE;
  300. }
  301. void main(int argc, char **argv)
  302. {
  303. GLenum type;
  304. if (Args(argc, argv) == GL_FALSE) {
  305. tkQuit();
  306. }
  307. tkInitPosition(0, 0, 300, 300);
  308. type = TK_RGB;
  309. type |= (doubleBuffer) ? TK_DOUBLE : TK_SINGLE;
  310. type |= (directRender) ? TK_DIRECT : TK_INDIRECT;
  311. tkInitDisplayMode(type);
  312. if (tkInitWindow("NURBS Test") == GL_FALSE) {
  313. tkQuit();
  314. }
  315. Init();
  316. tkExposeFunc(Reshape);
  317. tkReshapeFunc(Reshape);
  318. tkKeyDownFunc(Key);
  319. tkDisplayFunc(Draw);
  320. tkExec();
  321. }