Source code of Windows XP (NT5)
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.

233 lines
5.4 KiB

  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 CI_RED TK_RED
  42. #define CI_ANTI_ALIAS_GREEN 16
  43. #define CI_ANTI_ALIAS_YELLOW 32
  44. #define CI_ANTI_ALIAS_RED 48
  45. GLenum rgb, doubleBuffer, directRender, windType;
  46. GLint windW, windH;
  47. GLenum mode;
  48. GLint size;
  49. float point[3] = {
  50. 1.0, 1.0, 0.0
  51. };
  52. static void Init(void)
  53. {
  54. GLint i;
  55. glClearColor(0.0, 0.0, 0.0, 0.0);
  56. glBlendFunc(GL_SRC_ALPHA, GL_ZERO);
  57. if (!rgb) {
  58. for (i = 0; i < 16; i++) {
  59. tkSetOneColor(i+CI_ANTI_ALIAS_RED, i/15.0, 0.0, 0.0);
  60. tkSetOneColor(i+CI_ANTI_ALIAS_YELLOW, i/15.0, i/15.0, 0.0);
  61. tkSetOneColor(i+CI_ANTI_ALIAS_GREEN, 0.0, i/15.0, 0.0);
  62. }
  63. }
  64. mode = GL_FALSE;
  65. size = 1;
  66. }
  67. static void Reshape(int width, int height)
  68. {
  69. windW = (GLint)width;
  70. windH = (GLint)height;
  71. glViewport(0, 0, width, height);
  72. glMatrixMode(GL_PROJECTION);
  73. glLoadIdentity();
  74. gluOrtho2D(-windW/2, windW/2, -windH/2, windH/2);
  75. glMatrixMode(GL_MODELVIEW);
  76. }
  77. static GLenum Key(int key, GLenum mask)
  78. {
  79. switch (key) {
  80. case TK_ESCAPE:
  81. tkQuit();
  82. case TK_1:
  83. mode = !mode;
  84. break;
  85. case TK_W:
  86. size++;
  87. break;
  88. case TK_w:
  89. size--;
  90. if (size < 1) {
  91. size = 1;
  92. }
  93. break;
  94. case TK_LEFT:
  95. point[0] -= 0.25;
  96. break;
  97. case TK_RIGHT:
  98. point[0] += 0.25;
  99. break;
  100. case TK_UP:
  101. point[1] += 0.25;
  102. break;
  103. case TK_DOWN:
  104. point[1] -= 0.25;
  105. break;
  106. default:
  107. return GL_FALSE;
  108. }
  109. return GL_TRUE;
  110. }
  111. static void Draw(void)
  112. {
  113. glClear(GL_COLOR_BUFFER_BIT);
  114. TK_SETCOLOR(windType, TK_YELLOW);
  115. glBegin(GL_LINE_STRIP);
  116. glVertex2f(-windW/2, 0);
  117. glVertex2f(windW/2, 0);
  118. glEnd();
  119. glBegin(GL_LINE_STRIP);
  120. glVertex2f(0, -windH/2);
  121. glVertex2f(0, windH/2);
  122. glEnd();
  123. if (mode) {
  124. glEnable(GL_BLEND);
  125. glEnable(GL_POINT_SMOOTH);
  126. } else {
  127. glDisable(GL_BLEND);
  128. glDisable(GL_POINT_SMOOTH);
  129. }
  130. glPointSize(size);
  131. if (mode) {
  132. (rgb) ? glColor3f(1.0, 0.0, 0.0) : glIndexf(CI_ANTI_ALIAS_RED);
  133. } else {
  134. (rgb) ? glColor3f(1.0, 0.0, 0.0) : glIndexf(CI_RED);
  135. }
  136. glBegin(GL_POINTS);
  137. glVertex3fv(point);
  138. glEnd();
  139. glDisable(GL_POINT_SMOOTH);
  140. glPointSize(1);
  141. TK_SETCOLOR(windType, TK_GREEN);
  142. glBegin(GL_POINTS);
  143. glVertex3fv(point);
  144. glEnd();
  145. glFlush();
  146. if (doubleBuffer) {
  147. tkSwapBuffers();
  148. }
  149. }
  150. static GLenum Args(int argc, char **argv)
  151. {
  152. GLint i;
  153. rgb = GL_TRUE;
  154. doubleBuffer = GL_FALSE;
  155. directRender = GL_FALSE;
  156. for (i = 1; i < argc; i++) {
  157. if (strcmp(argv[i], "-ci") == 0) {
  158. rgb = GL_FALSE;
  159. } else if (strcmp(argv[i], "-rgb") == 0) {
  160. rgb = GL_TRUE;
  161. } else if (strcmp(argv[i], "-sb") == 0) {
  162. doubleBuffer = GL_FALSE;
  163. } else if (strcmp(argv[i], "-db") == 0) {
  164. doubleBuffer = GL_TRUE;
  165. } else if (strcmp(argv[i], "-dr") == 0) {
  166. directRender = GL_TRUE;
  167. } else if (strcmp(argv[i], "-ir") == 0) {
  168. directRender = GL_FALSE;
  169. } else {
  170. printf("%s (Bad option).\n", argv[i]);
  171. return GL_FALSE;
  172. }
  173. }
  174. return GL_TRUE;
  175. }
  176. void main(int argc, char **argv)
  177. {
  178. if (Args(argc, argv) == GL_FALSE) {
  179. tkQuit();
  180. }
  181. windW = 300;
  182. windH = 300;
  183. tkInitPosition(0, 0, windW, windH);
  184. windType = (rgb) ? TK_RGB : TK_INDEX;
  185. windType |= (doubleBuffer) ? TK_DOUBLE : TK_SINGLE;
  186. windType |= (directRender) ? TK_DIRECT : TK_INDIRECT;
  187. tkInitDisplayMode(windType);
  188. if (tkInitWindow("Point Test") == GL_FALSE) {
  189. tkQuit();
  190. }
  191. Init();
  192. tkExposeFunc(Reshape);
  193. tkReshapeFunc(Reshape);
  194. tkKeyDownFunc(Key);
  195. tkDisplayFunc(Draw);
  196. tkExec();
  197. }