Clone of mesa.
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.

stencil.c 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc.
  3. *
  4. * Permission to use, copy, modify, distribute, and sell this software and
  5. * its documentation for any purpose is hereby granted without fee, provided
  6. * that (i) the above copyright notices and this permission notice appear in
  7. * all copies of the software and related documentation, and (ii) the name of
  8. * Silicon Graphics may not be used in any advertising or
  9. * publicity relating to the software without the specific, prior written
  10. * permission of Silicon Graphics.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF
  13. * ANY KIND,
  14. * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
  15. * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  16. *
  17. * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR
  18. * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  19. * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  20. * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
  21. * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  22. * OF THIS SOFTWARE.
  23. */
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include <math.h>
  28. #include <GL/glut.h>
  29. static void Init(void)
  30. {
  31. glShadeModel(GL_FLAT);
  32. glClearColor(0.0, 0.0, 0.0, 0.0);
  33. glClearStencil(0);
  34. glStencilMask(1);
  35. glEnable(GL_STENCIL_TEST);
  36. }
  37. static void Reshape(int width, int height)
  38. {
  39. glViewport(0, 0, (GLint)width, (GLint)height);
  40. glMatrixMode(GL_PROJECTION);
  41. glLoadIdentity();
  42. glOrtho(-5.0, 5.0, -5.0, 5.0, -5.0, 5.0);
  43. glMatrixMode(GL_MODELVIEW);
  44. }
  45. static void Key(unsigned char key, int x, int y)
  46. {
  47. switch (key) {
  48. case 27:
  49. exit(1);
  50. }
  51. }
  52. static void Draw(void)
  53. {
  54. glClear(GL_COLOR_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
  55. glStencilFunc(GL_ALWAYS, 1, 1);
  56. glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
  57. glColor3ub(200, 0, 0);
  58. glBegin(GL_POLYGON);
  59. glVertex3i(-4, -4, 0);
  60. glVertex3i( 4, -4, 0);
  61. glVertex3i( 0, 4, 0);
  62. glEnd();
  63. glStencilFunc(GL_EQUAL, 1, 1);
  64. glStencilOp(GL_INCR, GL_KEEP, GL_DECR);
  65. glColor3ub(0, 200, 0);
  66. glBegin(GL_POLYGON);
  67. glVertex3i(3, 3, 0);
  68. glVertex3i(-3, 3, 0);
  69. glVertex3i(-3, -3, 0);
  70. glVertex3i(3, -3, 0);
  71. glEnd();
  72. glStencilFunc(GL_EQUAL, 1, 1);
  73. glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
  74. glColor3ub(0, 0, 200);
  75. glBegin(GL_POLYGON);
  76. glVertex3i(3, 3, 0);
  77. glVertex3i(-3, 3, 0);
  78. glVertex3i(-3, -3, 0);
  79. glVertex3i(3, -3, 0);
  80. glEnd();
  81. glFlush();
  82. }
  83. static GLenum Args(int argc, char **argv)
  84. {
  85. GLint i;
  86. for (i = 1; i < argc; i++) {
  87. if (strcmp(argv[i], "-dr") == 0) {
  88. } else {
  89. printf("%s (Bad option).\n", argv[i]);
  90. return GL_FALSE;
  91. }
  92. }
  93. return GL_TRUE;
  94. }
  95. int main(int argc, char **argv)
  96. {
  97. GLenum type;
  98. glutInit(&argc, argv);
  99. if (Args(argc, argv) == GL_FALSE) {
  100. exit(1);
  101. }
  102. glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300);
  103. type = GLUT_RGB | GLUT_SINGLE | GLUT_STENCIL;
  104. glutInitDisplayMode(type);
  105. if (glutCreateWindow("Stencil Test") == GL_FALSE) {
  106. exit(1);
  107. }
  108. Init();
  109. glutReshapeFunc(Reshape);
  110. glutKeyboardFunc(Key);
  111. glutDisplayFunc(Draw);
  112. glutMainLoop();
  113. return 0;
  114. }