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.

159 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. /* stencil.c
  38. * This program draws two rotated tori in a window.
  39. * A diamond in the center of the window masks out part
  40. * of the scene. Within this mask, a different model
  41. * (a sphere) is drawn in a different color.
  42. */
  43. #include <windows.h>
  44. #include <GL/gl.h>
  45. #include <GL/glu.h>
  46. #include "glaux.h"
  47. #define YELLOWMAT 1
  48. #define BLUEMAT 2
  49. void myinit (void)
  50. {
  51. GLfloat yellow_diffuse[] = { 0.7, 0.7, 0.0, 1.0 };
  52. GLfloat yellow_specular[] = { 1.0, 1.0, 1.0, 1.0 };
  53. GLfloat blue_diffuse[] = { 0.1, 0.1, 0.7, 1.0 };
  54. GLfloat blue_specular[] = { 0.1, 1.0, 1.0, 1.0 };
  55. GLfloat position_one[] = { 1.0, 1.0, 1.0, 0.0 };
  56. glNewList(YELLOWMAT, GL_COMPILE);
  57. glMaterialfv(GL_FRONT, GL_DIFFUSE, yellow_diffuse);
  58. glMaterialfv(GL_FRONT, GL_SPECULAR, yellow_specular);
  59. glMaterialf(GL_FRONT, GL_SHININESS, 64.0);
  60. glEndList();
  61. glNewList(BLUEMAT, GL_COMPILE);
  62. glMaterialfv(GL_FRONT, GL_DIFFUSE, blue_diffuse);
  63. glMaterialfv(GL_FRONT, GL_SPECULAR, blue_specular);
  64. glMaterialf(GL_FRONT, GL_SHININESS, 45.0);
  65. glEndList();
  66. glLightfv(GL_LIGHT0, GL_POSITION, position_one);
  67. glEnable(GL_LIGHT0);
  68. glEnable(GL_LIGHTING);
  69. glDepthFunc(GL_LESS);
  70. glEnable(GL_DEPTH_TEST);
  71. glClearStencil(0x0);
  72. glEnable(GL_STENCIL_TEST);
  73. }
  74. /* Draw a sphere in a diamond-shaped section in the
  75. * middle of a window with 2 tori.
  76. */
  77. void display(void)
  78. {
  79. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  80. /* draw blue sphere where the stencil is 1 */
  81. glStencilFunc (GL_EQUAL, 0x1, 0x1);
  82. glCallList (BLUEMAT);
  83. auxSolidSphere (0.5);
  84. /* draw the tori where the stencil is not 1 */
  85. glStencilFunc (GL_NOTEQUAL, 0x1, 0x1);
  86. glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);
  87. glPushMatrix();
  88. glRotatef (45.0, 0.0, 0.0, 1.0);
  89. glRotatef (45.0, 0.0, 1.0, 0.0);
  90. glCallList (YELLOWMAT);
  91. auxSolidTorus (0.275, 0.85);
  92. glPushMatrix();
  93. glRotatef (90.0, 1.0, 0.0, 0.0);
  94. auxSolidTorus (0.275, 0.85);
  95. glPopMatrix();
  96. glPopMatrix();
  97. glFlush();
  98. }
  99. /* Whenever the window is reshaped, redefine the
  100. * coordinate system and redraw the stencil area.
  101. */
  102. void myReshape(GLsizei w, GLsizei h)
  103. {
  104. glViewport(0, 0, w, h);
  105. glClear(GL_STENCIL_BUFFER_BIT);
  106. /* create a diamond shaped stencil area */
  107. glMatrixMode(GL_PROJECTION);
  108. glLoadIdentity();
  109. glOrtho(-3.0, 3.0, -3.0, 3.0, -1.0, 1.0);
  110. glMatrixMode(GL_MODELVIEW);
  111. glLoadIdentity();
  112. glStencilFunc (GL_ALWAYS, 0x1, 0x1);
  113. glStencilOp (GL_REPLACE, GL_REPLACE, GL_REPLACE);
  114. glBegin(GL_QUADS);
  115. glVertex3f (-1.0, 0.0, 0.0);
  116. glVertex3f (0.0, 1.0, 0.0);
  117. glVertex3f (1.0, 0.0, 0.0);
  118. glVertex3f (0.0, -1.0, 0.0);
  119. glEnd();
  120. glMatrixMode(GL_PROJECTION);
  121. glLoadIdentity();
  122. gluPerspective(45.0, (GLfloat) w/(GLfloat) h, 3.0, 7.0);
  123. glMatrixMode(GL_MODELVIEW);
  124. glLoadIdentity();
  125. glTranslatef(0.0, 0.0, -5.0);
  126. }
  127. /* Main Loop
  128. * Open window with initial window size, title bar,
  129. * RGBA display mode, and handle input events.
  130. */
  131. int main(int argc, char** argv)
  132. {
  133. auxInitDisplayMode (AUX_SINGLE | AUX_RGB
  134. | AUX_DEPTH16 | AUX_STENCIL);
  135. auxInitPosition (0, 0, 400, 400);
  136. auxInitWindow (argv[0]);
  137. myinit ();
  138. auxReshapeFunc (myReshape);
  139. auxMainLoop(display);
  140. }