Clone of mesa.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /**
  2. * Test glPolygonMode.
  3. * A tri-strip w/ two tris is drawn so that the first tri is front-facing
  4. * but the second tri is back-facing.
  5. * Set glPolygonMode differently for the front/back faces
  6. *
  7. */
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <math.h>
  11. #include <GL/glut.h>
  12. static int Win;
  13. static GLfloat Zrot = 0;
  14. static GLboolean FrontFillBackUnfilled = GL_TRUE;
  15. static GLboolean Lines = GL_TRUE;
  16. static void
  17. Draw(void)
  18. {
  19. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  20. if (FrontFillBackUnfilled) {
  21. if (Lines) {
  22. printf("FrontMode = FILL, BackMode = LINE\n");
  23. glPolygonMode(GL_BACK, GL_LINE);
  24. }
  25. else {
  26. printf("FrontMode = FILL, BackMode = POINT\n");
  27. glPolygonMode(GL_BACK, GL_POINT);
  28. }
  29. glPolygonMode(GL_FRONT, GL_FILL);
  30. }
  31. else {
  32. if (Lines) {
  33. printf("FrontMode = LINE, BackMode = FILL\n");
  34. glPolygonMode(GL_FRONT, GL_LINE);
  35. }
  36. else {
  37. printf("FrontMode = POINT, BackMode = FILL\n");
  38. glPolygonMode(GL_FRONT, GL_POINT);
  39. }
  40. glPolygonMode(GL_BACK, GL_FILL);
  41. }
  42. glPushMatrix();
  43. glRotatef(Zrot, 0, 0, 1);
  44. glBegin(GL_TRIANGLE_STRIP);
  45. glVertex2f(-1, 0);
  46. glVertex2f( 1, 0);
  47. glVertex2f(0, 1);
  48. glVertex2f(0, -1);
  49. glEnd();
  50. glPopMatrix();
  51. glutSwapBuffers();
  52. }
  53. static void
  54. Reshape(int width, int height)
  55. {
  56. glViewport(0, 0, width, height);
  57. glMatrixMode(GL_PROJECTION);
  58. glLoadIdentity();
  59. glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
  60. glMatrixMode(GL_MODELVIEW);
  61. glLoadIdentity();
  62. glTranslatef(0.0, 0.0, -15.0);
  63. }
  64. static void
  65. Key(unsigned char key, int x, int y)
  66. {
  67. const GLfloat step = 3.0;
  68. (void) x;
  69. (void) y;
  70. switch (key) {
  71. case 'p':
  72. FrontFillBackUnfilled = !FrontFillBackUnfilled;
  73. break;
  74. case 'l':
  75. Lines = !Lines;
  76. break;
  77. case 'z':
  78. Zrot -= step;
  79. break;
  80. case 'Z':
  81. Zrot += step;
  82. break;
  83. case 27:
  84. glutDestroyWindow(Win);
  85. exit(0);
  86. break;
  87. }
  88. glutPostRedisplay();
  89. }
  90. static void
  91. Init(void)
  92. {
  93. printf("GL_RENDERER = %s\n", (char*) glGetString(GL_RENDERER));
  94. glLineWidth(3.0);
  95. glPointSize(3.0);
  96. glColor4f(1, 1, 1, 0.8);
  97. glEnable(GL_BLEND);
  98. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  99. printf("Press 'p' to toggle polygon mode\n");
  100. }
  101. int
  102. main(int argc, char *argv[])
  103. {
  104. glutInit(&argc, argv);
  105. glutInitWindowPosition(0, 0);
  106. glutInitWindowSize(400, 400);
  107. glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
  108. Win = glutCreateWindow(argv[0]);
  109. glutReshapeFunc(Reshape);
  110. glutKeyboardFunc(Key);
  111. glutDisplayFunc(Draw);
  112. Init();
  113. glutMainLoop();
  114. return 0;
  115. }