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.

161 lines
4.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 <math.h>
  40. #include "tk.h"
  41. GLenum directRender;
  42. static void Init(void)
  43. {
  44. glClearColor(0.0, 0.0, 0.0, 0.0);
  45. glClearStencil(0);
  46. glStencilMask(1);
  47. glEnable(GL_STENCIL_TEST);
  48. }
  49. static void Reshape(int width, int height)
  50. {
  51. glViewport(0, 0, (GLint)width, (GLint)height);
  52. glMatrixMode(GL_PROJECTION);
  53. glLoadIdentity();
  54. glOrtho(-5.0, 5.0, -5.0, 5.0, -5.0, 5.0);
  55. glMatrixMode(GL_MODELVIEW);
  56. }
  57. static GLenum Key(int key, GLenum mask)
  58. {
  59. switch (key) {
  60. case TK_ESCAPE:
  61. tkQuit();
  62. }
  63. return GL_FALSE;
  64. }
  65. static void Draw(void)
  66. {
  67. glClear(GL_COLOR_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
  68. glStencilFunc(GL_ALWAYS, 1, 1);
  69. glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
  70. glColor3ub(200, 0, 0);
  71. glBegin(GL_POLYGON);
  72. glVertex3i(-4, -4, 0);
  73. glVertex3i( 4, -4, 0);
  74. glVertex3i( 0, 4, 0);
  75. glEnd();
  76. glStencilFunc(GL_EQUAL, 1, 1);
  77. glStencilOp(GL_INCR, GL_KEEP, GL_DECR);
  78. glColor3ub(0, 200, 0);
  79. glBegin(GL_POLYGON);
  80. glVertex3i(3, 3, 0);
  81. glVertex3i(-3, 3, 0);
  82. glVertex3i(-3, -3, 0);
  83. glVertex3i(3, -3, 0);
  84. glEnd();
  85. glStencilFunc(GL_EQUAL, 1, 1);
  86. glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
  87. glColor3ub(0, 0, 200);
  88. glBegin(GL_POLYGON);
  89. glVertex3i(3, 3, 0);
  90. glVertex3i(-3, 3, 0);
  91. glVertex3i(-3, -3, 0);
  92. glVertex3i(3, -3, 0);
  93. glEnd();
  94. glFlush();
  95. }
  96. static GLenum Args(int argc, char **argv)
  97. {
  98. GLint i;
  99. directRender = GL_FALSE;
  100. for (i = 1; i < argc; i++) {
  101. if (strcmp(argv[i], "-dr") == 0) {
  102. directRender = GL_TRUE;
  103. } else if (strcmp(argv[i], "-ir") == 0) {
  104. directRender = GL_FALSE;
  105. } else {
  106. printf("%s (Bad option).\n", argv[i]);
  107. return GL_FALSE;
  108. }
  109. }
  110. return GL_TRUE;
  111. }
  112. void main(int argc, char **argv)
  113. {
  114. GLenum type;
  115. if (Args(argc, argv) == GL_FALSE) {
  116. tkQuit();
  117. }
  118. tkInitPosition(0, 0, 300, 300);
  119. type = TK_RGB | TK_SINGLE | TK_STENCIL;
  120. type |= (directRender) ? TK_DIRECT : TK_INDIRECT;
  121. tkInitDisplayMode(type);
  122. if (tkInitWindow("Stencil Test") == GL_FALSE) {
  123. tkQuit();
  124. }
  125. Init();
  126. tkExposeFunc(Reshape);
  127. tkReshapeFunc(Reshape);
  128. tkKeyDownFunc(Key);
  129. tkDisplayFunc(Draw);
  130. tkExec();
  131. }