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.

unfilledclip.c 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * Copyright © 2008 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. * IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Eric Anholt <eric@anholt.net>
  25. *
  26. */
  27. #include <stdlib.h>
  28. #include <GL/glew.h>
  29. #include <GL/glut.h>
  30. static int win_width, win_height;
  31. #if 0
  32. static void
  33. line(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
  34. {
  35. glBegin(GL_LINES);
  36. glVertex2f(x1, y1);
  37. glVertex2f(x2, y2);
  38. glEnd();
  39. }
  40. #endif
  41. static void
  42. line3(GLfloat x1, GLfloat y1, GLfloat z1, GLfloat x2, GLfloat y2, GLfloat z2)
  43. {
  44. glBegin(GL_LINES);
  45. glVertex3f(x1, y1, z1);
  46. glVertex3f(x2, y2, z2);
  47. glEnd();
  48. }
  49. static void
  50. display(void)
  51. {
  52. glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  53. glClearColor(0.0, 0.0, 0.0, 0.0);
  54. glClear(GL_COLOR_BUFFER_BIT);
  55. glColor3f(1.0, 0.0, 0.0);
  56. /* clipped along xmin */
  57. glBegin(GL_TRIANGLES);
  58. glVertex2f(-20, win_height / 2 - 20);
  59. glVertex2f(20, win_height / 2);
  60. glVertex2f(-20, win_height / 2 + 20);
  61. glEnd();
  62. glColor3f(0.0, 1.0, 0.0);
  63. /* clipped along ymax */
  64. glBegin(GL_TRIANGLES);
  65. glVertex2f(win_height / 2 - 20, win_height + 20);
  66. glVertex2f(win_height / 2, win_height - 20);
  67. glVertex2f(win_height / 2 + 20, win_height + 20);
  68. glEnd();
  69. glColor3f(0.0, 0.0, 1.0);
  70. /* clipped along xmax */
  71. glBegin(GL_TRIANGLES);
  72. glVertex2f(win_height + 20, win_height / 2 - 20);
  73. glVertex2f(win_height - 20, win_height / 2);
  74. glVertex2f(win_height + 20, win_height / 2 + 20);
  75. glEnd();
  76. glColor3f(1.0, 1.0, 1.0);
  77. /* clipped along ymin */
  78. glBegin(GL_TRIANGLES);
  79. glVertex2f(win_height / 2 - 20, -20);
  80. glVertex2f(win_height / 2, 20);
  81. glVertex2f(win_height / 2 + 20, -20);
  82. glEnd();
  83. /* clipped along near */
  84. glColor3f(1.0, 0.0, 1.0);
  85. glBegin(GL_TRIANGLES);
  86. glVertex3f(win_width / 2 - 20, win_height / 2 - 20, 0.5);
  87. glVertex3f(win_width / 2 - 40, win_height / 2, -0.5);
  88. glVertex3f(win_width / 2 - 20, win_height / 2 + 20, 0.5);
  89. glEnd();
  90. /* clipped along far */
  91. glColor3f(0.0, 1.0, 1.0);
  92. glBegin(GL_TRIANGLES);
  93. glVertex3f(win_width / 2 + 20, win_height / 2 - 20, 0.5);
  94. glVertex3f(win_width / 2 + 40, win_height / 2, 1.5);
  95. glVertex3f(win_width / 2 + 20, win_height / 2 + 20, 0.5);
  96. glEnd();
  97. /* entirely clipped along near/far */
  98. glColor3f(.5, .5, .5);
  99. glBegin(GL_TRIANGLES);
  100. glVertex3f(win_width / 2 - 20, win_height / 2 + 20, -0.5);
  101. glVertex3f(win_width / 2, win_height / 2 + 40, -0.5);
  102. glVertex3f(win_width / 2 + 20, win_height / 2 + 20, -0.5);
  103. glEnd();
  104. glBegin(GL_TRIANGLES);
  105. glVertex3f(win_width / 2 - 20, win_height / 2 - 20, 1.5);
  106. glVertex3f(win_width / 2, win_height / 2 - 40, 1.5);
  107. glVertex3f(win_width / 2 + 20, win_height / 2 - 20, 1.5);
  108. glEnd();
  109. glColor3f(.5, .5, .5);
  110. line3(win_width / 2, win_height / 2 - 20, 1.5,
  111. win_width / 2, win_height / 2 + 20, 1.5);
  112. glColor3f(1.0, 1.0, 0.0);
  113. /* clipped along both x and y limits */
  114. glBegin(GL_TRIANGLES); /* xmin, ymin */
  115. glVertex2f(-5, 20);
  116. glVertex2f(20, 20);
  117. glVertex2f(20, -5);
  118. glEnd();
  119. glBegin(GL_TRIANGLES); /* xmin, ymax */
  120. glVertex2f(-5, win_height - 20);
  121. glVertex2f(20, win_height - 20);
  122. glVertex2f(20, win_height + 5);
  123. glEnd();
  124. glBegin(GL_TRIANGLES); /* xmax, ymax */
  125. glVertex2f(win_width - 20, win_height + 5);
  126. glVertex2f(win_width - 20, win_height - 20);
  127. glVertex2f(win_width + 5, win_height - 20);
  128. glEnd();
  129. glBegin(GL_TRIANGLES); /* xmax, ymin */
  130. glVertex2f(win_width + 5, 20);
  131. glVertex2f(win_width - 20, 20);
  132. glVertex2f(win_width - 20, -5);
  133. glEnd();
  134. glutSwapBuffers();
  135. }
  136. static void
  137. reshape(int width, int height)
  138. {
  139. win_width = width;
  140. win_height = height;
  141. glViewport(0, 0, width, height);
  142. glMatrixMode(GL_PROJECTION);
  143. glLoadIdentity();
  144. glOrtho(0, win_width, 0, win_height, 0.0, -1.0);
  145. glMatrixMode(GL_MODELVIEW);
  146. glLoadIdentity();
  147. glTranslatef(.25, .25, 0);
  148. }
  149. static void key( unsigned char key, int x, int y )
  150. {
  151. (void) x;
  152. (void) y;
  153. switch (key) {
  154. case 27: /* esc */
  155. exit(0);
  156. break;
  157. }
  158. glutPostRedisplay();
  159. }
  160. static void
  161. init(void)
  162. {
  163. }
  164. int
  165. main(int argc, char *argv[])
  166. {
  167. win_width = 200;
  168. win_height = 200;
  169. glutInit(&argc, argv);
  170. glutInitWindowPosition(0, 0);
  171. glutInitWindowSize(win_width, win_height);
  172. glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
  173. glutCreateWindow(argv[0]);
  174. glewInit();
  175. glutReshapeFunc(reshape);
  176. glutKeyboardFunc(key);
  177. glutDisplayFunc(display);
  178. init();
  179. glutMainLoop();
  180. return 0;
  181. }