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.

dlist-degenerate.c 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /**
  2. * Test display list corner cases.
  3. */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <math.h>
  7. #include <GL/glut.h>
  8. static int Win;
  9. static GLfloat Xrot = 0, Yrot = 0, Zrot = 0;
  10. static GLboolean Anim = GL_FALSE;
  11. static GLuint List1 = 0, List2 = 0;
  12. static void
  13. Idle(void)
  14. {
  15. Xrot += 3.0;
  16. Yrot += 4.0;
  17. Zrot += 2.0;
  18. glutPostRedisplay();
  19. }
  20. static void
  21. Draw(void)
  22. {
  23. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  24. glPushMatrix();
  25. glRotatef(Xrot, 1, 0, 0);
  26. glRotatef(Yrot, 0, 1, 0);
  27. glRotatef(Zrot, 0, 0, 1);
  28. glCallList(List1);
  29. glCallList(List2);
  30. glPopMatrix();
  31. glutSwapBuffers();
  32. }
  33. static void
  34. Reshape(int width, int height)
  35. {
  36. glViewport(0, 0, width, height);
  37. glMatrixMode(GL_PROJECTION);
  38. glLoadIdentity();
  39. glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
  40. glMatrixMode(GL_MODELVIEW);
  41. glLoadIdentity();
  42. glTranslatef(0.0, 0.0, -15.0);
  43. }
  44. static void
  45. Key(unsigned char key, int x, int y)
  46. {
  47. const GLfloat step = 3.0;
  48. (void) x;
  49. (void) y;
  50. switch (key) {
  51. case 'a':
  52. Anim = !Anim;
  53. if (Anim)
  54. glutIdleFunc(Idle);
  55. else
  56. glutIdleFunc(NULL);
  57. break;
  58. case 'z':
  59. Zrot -= step;
  60. break;
  61. case 'Z':
  62. Zrot += step;
  63. break;
  64. case 27:
  65. glutDestroyWindow(Win);
  66. exit(0);
  67. break;
  68. }
  69. glutPostRedisplay();
  70. }
  71. static void
  72. SpecialKey(int key, int x, int y)
  73. {
  74. const GLfloat step = 3.0;
  75. (void) x;
  76. (void) y;
  77. switch (key) {
  78. case GLUT_KEY_UP:
  79. Xrot -= step;
  80. break;
  81. case GLUT_KEY_DOWN:
  82. Xrot += step;
  83. break;
  84. case GLUT_KEY_LEFT:
  85. Yrot -= step;
  86. break;
  87. case GLUT_KEY_RIGHT:
  88. Yrot += step;
  89. break;
  90. }
  91. glutPostRedisplay();
  92. }
  93. static void
  94. Init(void)
  95. {
  96. /* List1: start of primitive */
  97. List1 = glGenLists(1);
  98. glNewList(List1, GL_COMPILE);
  99. glBegin(GL_POLYGON);
  100. glVertex2f(-1, -1);
  101. glVertex2f( 1, -1);
  102. glEndList();
  103. /* List2: end of primitive */
  104. List2 = glGenLists(1);
  105. glNewList(List2, GL_COMPILE);
  106. glVertex2f( 1, 1);
  107. glVertex2f(-1, 1);
  108. glEnd();
  109. glEndList();
  110. glEnable(GL_DEPTH_TEST);
  111. }
  112. int
  113. main(int argc, char *argv[])
  114. {
  115. glutInit(&argc, argv);
  116. glutInitWindowPosition(0, 0);
  117. glutInitWindowSize(400, 400);
  118. glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
  119. Win = glutCreateWindow(argv[0]);
  120. glutReshapeFunc(Reshape);
  121. glutKeyboardFunc(Key);
  122. glutSpecialFunc(SpecialKey);
  123. glutDisplayFunc(Draw);
  124. if (Anim)
  125. glutIdleFunc(Idle);
  126. Init();
  127. glutMainLoop();
  128. return 0;
  129. }