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.

230 lines
5.1 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_OFFSET 16
  42. GLenum rgb, doubleBuffer, directRender, windType;
  43. GLenum mode1, mode2;
  44. GLint size;
  45. float pntA[3] = {
  46. -160.0, 0.0, 0.0
  47. };
  48. float pntB[3] = {
  49. -130.0, 0.0, 0.0
  50. };
  51. float pntC[3] = {
  52. -40.0, -50.0, 0.0
  53. };
  54. float pntD[3] = {
  55. 30.0, 60.0, 0.0
  56. };
  57. static void Init(void)
  58. {
  59. GLint i;
  60. glClearColor(0.0, 0.0, 0.0, 0.0);
  61. glLineStipple(1, 0xF0E0);
  62. glBlendFunc(GL_SRC_ALPHA, GL_ONE);
  63. if (!rgb) {
  64. for (i = 0; i < 16; i++) {
  65. tkSetOneColor(i+CI_OFFSET, i/15.0, i/15.0, 0.0);
  66. }
  67. }
  68. mode1 = GL_FALSE;
  69. mode2 = GL_FALSE;
  70. size = 1;
  71. }
  72. static void Reshape(int width, int height)
  73. {
  74. glViewport(0, 0, (GLint)width, (GLint)height);
  75. glMatrixMode(GL_PROJECTION);
  76. glLoadIdentity();
  77. gluOrtho2D(-175, 175, -175, 175);
  78. glMatrixMode(GL_MODELVIEW);
  79. }
  80. static GLenum Key(int key, GLenum mask)
  81. {
  82. switch (key) {
  83. case TK_ESCAPE:
  84. tkQuit();
  85. case TK_1:
  86. mode1 = !mode1;
  87. break;
  88. case TK_2:
  89. mode2 = !mode2;
  90. break;
  91. case TK_W:
  92. size++;
  93. break;
  94. case TK_w:
  95. size--;
  96. if (size < 1) {
  97. size = 1;
  98. }
  99. break;
  100. default:
  101. return GL_FALSE;
  102. }
  103. return GL_TRUE;
  104. }
  105. static void Draw(void)
  106. {
  107. GLint ci, i;
  108. glClear(GL_COLOR_BUFFER_BIT);
  109. glLineWidth(size);
  110. if (mode1) {
  111. glEnable(GL_LINE_STIPPLE);
  112. } else {
  113. glDisable(GL_LINE_STIPPLE);
  114. }
  115. if (mode2) {
  116. ci = CI_OFFSET;
  117. glEnable(GL_LINE_SMOOTH);
  118. glEnable(GL_BLEND);
  119. } else {
  120. ci = TK_YELLOW;
  121. glDisable(GL_LINE_SMOOTH);
  122. glDisable(GL_BLEND);
  123. }
  124. glPushMatrix();
  125. for (i = 0; i < 360; i += 5) {
  126. glRotatef(5.0, 0,0,1);
  127. (rgb) ? glColor3f(1.0, 1.0, 0.0) : glIndexi(ci);
  128. glBegin(GL_LINE_STRIP);
  129. glVertex3fv(pntA);
  130. glVertex3fv(pntB);
  131. glEnd();
  132. glPointSize(1);
  133. TK_SETCOLOR(windType, TK_GREEN);
  134. glBegin(GL_POINTS);
  135. glVertex3fv(pntA);
  136. glVertex3fv(pntB);
  137. glEnd();
  138. }
  139. glPopMatrix();
  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. if (Args(argc, argv) == GL_FALSE) {
  174. tkQuit();
  175. }
  176. tkInitPosition(0, 0, 300, 300);
  177. windType = TK_ALPHA;
  178. windType |= (rgb) ? TK_RGB : TK_INDEX;
  179. windType |= (doubleBuffer) ? TK_DOUBLE : TK_SINGLE;
  180. windType |= (directRender) ? TK_DIRECT : TK_INDIRECT;
  181. tkInitDisplayMode(windType);
  182. if (tkInitWindow("Line Test") == GL_FALSE) {
  183. tkQuit();
  184. }
  185. Init();
  186. tkExposeFunc(Reshape);
  187. tkReshapeFunc(Reshape);
  188. tkKeyDownFunc(Key);
  189. tkDisplayFunc(Draw);
  190. tkExec();
  191. }