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.

depth.c 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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 <string.h>
  26. #include <stdlib.h>
  27. #include <GL/glut.h>
  28. #define CI_OFFSET_1 16
  29. #define CI_OFFSET_2 32
  30. GLenum rgb, doubleBuffer;
  31. GLenum antiAlias, stipple;
  32. GLubyte stippleBits[32*4] = {
  33. 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
  34. 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
  35. 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
  36. 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
  37. 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
  38. 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
  39. 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
  40. 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
  41. 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
  42. 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
  43. 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
  44. 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
  45. 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
  46. 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
  47. 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
  48. 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
  49. };
  50. #include "tkmap.c"
  51. static void Init(void)
  52. {
  53. GLint i;
  54. glClearColor(0.0, 0.0, 0.0, 0.0);
  55. glClearIndex(0.0);
  56. if (!rgb) {
  57. for (i = 0; i < 16; i++) {
  58. glutSetColor(i+CI_OFFSET_1, 0.0, 0.0, i/15.0);
  59. glutSetColor(i+CI_OFFSET_2, 0.0, i/15.0, 0.0);
  60. }
  61. }
  62. glPolygonStipple(stippleBits);
  63. antiAlias = GL_FALSE;
  64. stipple = GL_FALSE;
  65. }
  66. static void Reshape(int width, int height)
  67. {
  68. glViewport(0, 0, (GLint)width, (GLint)height);
  69. glMatrixMode(GL_PROJECTION);
  70. glLoadIdentity();
  71. glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
  72. glMatrixMode(GL_MODELVIEW);
  73. }
  74. static void Key(unsigned char key, int x, int y)
  75. {
  76. switch (key) {
  77. case 27:
  78. exit(1);
  79. case '1':
  80. antiAlias = !antiAlias;
  81. break;
  82. case '2':
  83. stipple = !stipple;
  84. break;
  85. default:
  86. return;
  87. }
  88. glutPostRedisplay();
  89. }
  90. static void Draw(void)
  91. {
  92. GLint ci1, ci2;
  93. glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  94. if (antiAlias) {
  95. ci1 = CI_OFFSET_1;
  96. ci2 = CI_OFFSET_2;
  97. glBlendFunc(GL_SRC_ALPHA, GL_ONE);
  98. glEnable(GL_BLEND);
  99. glEnable(GL_POLYGON_SMOOTH);
  100. glDisable(GL_DEPTH_TEST);
  101. } else {
  102. ci1 = COLOR_BLUE;
  103. ci2 = COLOR_GREEN;
  104. glDisable(GL_BLEND);
  105. glDisable(GL_POLYGON_SMOOTH);
  106. glEnable(GL_DEPTH_TEST);
  107. }
  108. if (stipple) {
  109. glEnable(GL_POLYGON_STIPPLE);
  110. } else {
  111. glDisable(GL_POLYGON_STIPPLE);
  112. }
  113. glBegin(GL_TRIANGLES);
  114. (rgb) ? glColor3fv(RGBMap[COLOR_BLUE]) : glIndexi(ci1);
  115. glVertex3f( 0.9, -0.9, -30.0);
  116. glVertex3f( 0.9, 0.9, -30.0);
  117. glVertex3f(-0.9, 0.0, -30.0);
  118. (rgb) ? glColor3fv(RGBMap[COLOR_GREEN]) : glIndexi(ci2);
  119. glVertex3f(-0.9, -0.9, -40.0);
  120. glVertex3f(-0.9, 0.9, -40.0);
  121. glVertex3f( 0.9, 0.0, -25.0);
  122. glEnd();
  123. glFlush();
  124. if (doubleBuffer) {
  125. glutSwapBuffers();
  126. }
  127. }
  128. static GLenum Args(int argc, char **argv)
  129. {
  130. GLint i;
  131. rgb = GL_TRUE;
  132. doubleBuffer = GL_FALSE;
  133. for (i = 1; i < argc; i++) {
  134. if (strcmp(argv[i], "-ci") == 0) {
  135. rgb = GL_FALSE;
  136. } else if (strcmp(argv[i], "-rgb") == 0) {
  137. rgb = GL_TRUE;
  138. } else if (strcmp(argv[i], "-sb") == 0) {
  139. doubleBuffer = GL_FALSE;
  140. } else if (strcmp(argv[i], "-db") == 0) {
  141. doubleBuffer = GL_TRUE;
  142. } else {
  143. printf("%s (Bad option).\n", argv[i]);
  144. return GL_FALSE;
  145. }
  146. }
  147. return GL_TRUE;
  148. }
  149. int main(int argc, char **argv)
  150. {
  151. GLenum type;
  152. glutInit(&argc, argv);
  153. if (Args(argc, argv) == GL_FALSE) {
  154. exit(1);
  155. }
  156. glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300);
  157. type = GLUT_DEPTH;
  158. type |= (rgb) ? GLUT_RGB : GLUT_INDEX;
  159. type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
  160. glutInitDisplayMode(type);
  161. if (glutCreateWindow("Depth Test") == GL_FALSE) {
  162. exit(1);
  163. }
  164. InitMap();
  165. Init();
  166. glutReshapeFunc(Reshape);
  167. glutKeyboardFunc(Key);
  168. glutDisplayFunc(Draw);
  169. glutMainLoop();
  170. return 0;
  171. }