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.

224 lines
5.9 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. #if 0
  42. #define CI_OFFSET_1 16
  43. #define CI_OFFSET_2 32
  44. #else
  45. #define CI_OFFSET_1 32
  46. #define CI_OFFSET_2 48
  47. #endif
  48. GLenum rgb, doubleBuffer, directRender;
  49. GLenum antiAlias, stipple;
  50. GLubyte stippleBits[32*4] = {
  51. 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
  52. 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
  53. 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
  54. 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
  55. 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
  56. 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
  57. 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
  58. 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
  59. 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
  60. 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
  61. 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
  62. 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
  63. 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
  64. 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
  65. 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
  66. 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
  67. };
  68. static void Init(void)
  69. {
  70. GLint i;
  71. glClearColor(0.0, 0.0, 0.0, 0.0);
  72. glClearIndex(0.0);
  73. if (!rgb) {
  74. for (i = 0; i < 16; i++) {
  75. tkSetOneColor(i+CI_OFFSET_1, 0.0, 0.0, i/15.0);
  76. tkSetOneColor(i+CI_OFFSET_2, 0.0, i/15.0, 0.0);
  77. }
  78. }
  79. antiAlias = GL_FALSE;
  80. stipple = GL_FALSE;
  81. }
  82. static void Reshape(int width, int height)
  83. {
  84. glViewport(0, 0, (GLint)width, (GLint)height);
  85. glMatrixMode(GL_PROJECTION);
  86. glLoadIdentity();
  87. glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
  88. glMatrixMode(GL_MODELVIEW);
  89. }
  90. static GLenum Key(int key, GLenum mask)
  91. {
  92. switch (key) {
  93. case TK_ESCAPE:
  94. tkQuit();
  95. case TK_1:
  96. antiAlias = !antiAlias;
  97. break;
  98. case TK_2:
  99. stipple = !stipple;
  100. break;
  101. default:
  102. return GL_FALSE;
  103. }
  104. return GL_TRUE;
  105. }
  106. static void Draw(void)
  107. {
  108. GLint ci1, ci2;
  109. glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  110. if (antiAlias) {
  111. ci1 = CI_OFFSET_1;
  112. ci2 = CI_OFFSET_2;
  113. glBlendFunc(GL_SRC_ALPHA, GL_ONE);
  114. glEnable(GL_BLEND);
  115. glEnable(GL_POLYGON_SMOOTH);
  116. glDisable(GL_DEPTH_TEST);
  117. } else {
  118. ci1 = TK_BLUE;
  119. ci2 = TK_GREEN;
  120. glDisable(GL_BLEND);
  121. glDisable(GL_POLYGON_SMOOTH);
  122. glEnable(GL_DEPTH_TEST);
  123. }
  124. if (stipple) {
  125. glPolygonStipple(stippleBits);
  126. glEnable(GL_POLYGON_STIPPLE);
  127. } else {
  128. glDisable(GL_POLYGON_STIPPLE);
  129. }
  130. glBegin(GL_TRIANGLES);
  131. (rgb) ? glColor3fv(tkRGBMap[TK_BLUE]) : glIndexi(ci1);
  132. glVertex3f( 0.9, -0.9, -30.0);
  133. glVertex3f( 0.9, 0.9, -30.0);
  134. glVertex3f(-0.9, 0.0, -30.0);
  135. (rgb) ? glColor3fv(tkRGBMap[TK_GREEN]) : glIndexi(ci2);
  136. glVertex3f(-0.9, -0.9, -40.0);
  137. glVertex3f(-0.9, 0.9, -40.0);
  138. glVertex3f( 0.9, 0.0, -25.0);
  139. glEnd();
  140. glFlush();
  141. if (doubleBuffer) {
  142. tkSwapBuffers();
  143. }
  144. }
  145. static GLenum Args(int argc, char **argv)
  146. {
  147. GLint i;
  148. rgb = GL_TRUE;
  149. doubleBuffer = GL_FALSE;
  150. directRender = GL_FALSE;
  151. for (i = 1; i < argc; i++) {
  152. if (strcmp(argv[i], "-ci") == 0) {
  153. rgb = GL_FALSE;
  154. } else if (strcmp(argv[i], "-rgb") == 0) {
  155. rgb = GL_TRUE;
  156. } else if (strcmp(argv[i], "-sb") == 0) {
  157. doubleBuffer = GL_FALSE;
  158. } else if (strcmp(argv[i], "-db") == 0) {
  159. doubleBuffer = GL_TRUE;
  160. } else if (strcmp(argv[i], "-dr") == 0) {
  161. directRender = GL_TRUE;
  162. } else if (strcmp(argv[i], "-ir") == 0) {
  163. directRender = GL_FALSE;
  164. } else {
  165. printf("%s (Bad option).\n", argv[i]);
  166. return GL_FALSE;
  167. }
  168. }
  169. return GL_TRUE;
  170. }
  171. void main(int argc, char **argv)
  172. {
  173. GLenum type;
  174. if (Args(argc, argv) == GL_FALSE) {
  175. tkQuit();
  176. }
  177. tkInitPosition(0, 0, 300, 300);
  178. type = TK_ALPHA | TK_DEPTH16;
  179. type |= (rgb) ? TK_RGB : TK_INDEX;
  180. type |= (doubleBuffer) ? TK_DOUBLE : TK_SINGLE;
  181. type |= (directRender) ? TK_DIRECT : TK_INDIRECT;
  182. tkInitDisplayMode(type);
  183. if (tkInitWindow("Depth Test") == GL_FALSE) {
  184. tkQuit();
  185. }
  186. Init();
  187. tkExposeFunc(Reshape);
  188. tkReshapeFunc(Reshape);
  189. tkKeyDownFunc(Key);
  190. tkDisplayFunc(Draw);
  191. tkExec();
  192. }