Clone of mesa.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

tri-stencil.c 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. }
  32. static void Reshape(int width, int height)
  33. {
  34. glViewport(0, 0, (GLint)width, (GLint)height);
  35. glMatrixMode(GL_PROJECTION);
  36. glLoadIdentity();
  37. glOrtho(-5.0, 5.0, -5.0, 5.0, -5.0, 5.0);
  38. glMatrixMode(GL_MODELVIEW);
  39. }
  40. static void Key(unsigned char key, int x, int y)
  41. {
  42. switch (key) {
  43. case 27:
  44. printf("Exiting...\n");
  45. exit(1);
  46. case 'r':
  47. printf("Redisplaying...\n");
  48. glutPostRedisplay();
  49. break;
  50. default:
  51. printf("No such key '%c'...\n", key);
  52. break;
  53. }
  54. }
  55. static void Draw(void)
  56. {
  57. glShadeModel(GL_FLAT);
  58. {
  59. glClearColor(0.0, 0.0, 0.0, 0.0);
  60. glClearStencil(0);
  61. glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
  62. }
  63. glStencilMask(1);
  64. glEnable(GL_STENCIL_TEST);
  65. glStencilFunc(GL_ALWAYS, 1, 1);
  66. glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
  67. glColor3ub(200, 0, 0);
  68. glBegin(GL_POLYGON);
  69. glVertex3i(-4, -4, 0);
  70. glVertex3i( 4, -4, 0);
  71. glVertex3i( 0, 4, 0);
  72. glEnd();
  73. #if 1
  74. glStencilFunc(GL_EQUAL, 1, 1);
  75. glStencilOp(GL_INCR, GL_KEEP, GL_DECR);
  76. glColor3ub(0, 200, 0);
  77. glBegin(GL_POLYGON);
  78. glVertex3i(3, 3, 0);
  79. glVertex3i(-3, 3, 0);
  80. glVertex3i(-3, -3, 0);
  81. glVertex3i(3, -3, 0);
  82. glEnd();
  83. #endif
  84. #if 1
  85. glStencilFunc(GL_EQUAL, 1, 1);
  86. glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
  87. glColor3ub(0, 0, 200);
  88. glBegin(GL_POLYGON);
  89. glVertex3f(2.5, 2.5, 0);
  90. glVertex3f(-2.5, 2.5, 0);
  91. glVertex3f(-2.5, -2.5, 0);
  92. glVertex3f(2.5, -2.5, 0);
  93. glEnd();
  94. #endif
  95. glFlush();
  96. }
  97. static GLenum Args(int argc, char **argv)
  98. {
  99. GLint i;
  100. for (i = 1; i < argc; i++) {
  101. if (strcmp(argv[i], "-dr") == 0) {
  102. } else {
  103. printf("%s (Bad option).\n", argv[i]);
  104. return GL_FALSE;
  105. }
  106. }
  107. return GL_TRUE;
  108. }
  109. int main(int argc, char **argv)
  110. {
  111. GLenum type;
  112. glutInit(&argc, argv);
  113. if (Args(argc, argv) == GL_FALSE) {
  114. exit(1);
  115. }
  116. glutInitWindowPosition(0, 0);
  117. glutInitWindowSize( 300, 300);
  118. type = GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH | GLUT_STENCIL;
  119. glutInitDisplayMode(type);
  120. if (glutCreateWindow(*argv) == GL_FALSE) {
  121. exit(1);
  122. }
  123. Init();
  124. glutReshapeFunc(Reshape);
  125. glutKeyboardFunc(Key);
  126. glutDisplayFunc(Draw);
  127. glutMainLoop();
  128. return 0;
  129. }