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.

tri-point-line-clipped.c 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**
  2. * Test frustum/user clipping w/ glPolygonMode LINE/POINT.
  3. *
  4. * The bottom/left and bottom/right verts are outside the frustum and clipped.
  5. * The top vertex is clipped by a user clipping plane.
  6. *
  7. * A filled gray reference triangle is shown underneath the points/lines.
  8. */
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <GL/glut.h>
  12. static int win;
  13. static void
  14. ColorTri(void)
  15. {
  16. glBegin(GL_TRIANGLES);
  17. glColor3f(1, 0, 0); glVertex3f(-1.5, -0.8, 0.0);
  18. glColor3f(0, 1, 0); glVertex3f( 1.5, -0.8, 0.0);
  19. glColor3f(0, 0, 1); glVertex3f( 0.0, 0.9, 0.0);
  20. glEnd();
  21. }
  22. static void
  23. GrayTri(void)
  24. {
  25. glColor3f(0.3, 0.3, 0.3);
  26. glBegin(GL_TRIANGLES);
  27. glVertex3f(-1.5, -0.8, 0.0);
  28. glVertex3f( 1.5, -0.8, 0.0);
  29. glVertex3f( 0.0, 0.9, 0.0);
  30. glEnd();
  31. }
  32. static void
  33. Draw(void)
  34. {
  35. static const GLdouble plane[4] = { 0, -1.0, 0, 0.5 };
  36. glClear(GL_COLOR_BUFFER_BIT);
  37. glPointSize(13.0);
  38. glLineWidth(5.0);
  39. glClipPlane(GL_CLIP_PLANE0, plane);
  40. glEnable(GL_CLIP_PLANE0);
  41. glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  42. GrayTri();
  43. glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  44. ColorTri();
  45. glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
  46. ColorTri();
  47. glutSwapBuffers();
  48. }
  49. static void Reshape(int width, int height)
  50. {
  51. glViewport(0, 0, (GLint)width, (GLint)height);
  52. glMatrixMode(GL_PROJECTION);
  53. glLoadIdentity();
  54. glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
  55. glMatrixMode(GL_MODELVIEW);
  56. }
  57. static void
  58. Key(unsigned char key, int x, int y)
  59. {
  60. if (key == 27) {
  61. glutDestroyWindow(win);
  62. exit(0);
  63. }
  64. else {
  65. glutPostRedisplay();
  66. }
  67. }
  68. static void
  69. Init(void)
  70. {
  71. fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  72. fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
  73. fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
  74. fflush(stderr);
  75. }
  76. int
  77. main(int argc, char **argv)
  78. {
  79. glutInitWindowSize(300, 300);
  80. glutInit(&argc, argv);
  81. glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
  82. win = glutCreateWindow(*argv);
  83. if (!win) {
  84. return 1;
  85. }
  86. Init();
  87. glutReshapeFunc(Reshape);
  88. glutKeyboardFunc(Key);
  89. glutDisplayFunc(Draw);
  90. glutMainLoop();
  91. return 0;
  92. }