Source code of Windows XP (NT5)
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.

154 lines
2.5 KiB

  1. #include <stdio.h>
  2. #include <windows.h>
  3. #include <gl\gl.h>
  4. #include <gl\glaux.h>
  5. BOOL fDouble = FALSE;
  6. int nIter = 128;
  7. #define WIDTH 512
  8. #define HEIGHT 512
  9. double clip_val;
  10. #define CLIP clip_val
  11. #define CLIP_CENTER 1
  12. void Draw(void)
  13. {
  14. glLoadIdentity();
  15. glBegin(GL_LINES);
  16. glVertex2d(-CLIP, -CLIP);
  17. glVertex2d(CLIP, CLIP);
  18. glVertex2d(-CLIP, CLIP);
  19. glVertex2d(CLIP, -CLIP);
  20. glEnd();
  21. glBegin(GL_LINE_LOOP);
  22. glVertex2d(0, .25);
  23. glVertex2d(-CLIP, CLIP);
  24. glVertex2d(-.25, 0);
  25. glVertex2d(-CLIP, -CLIP);
  26. glVertex2d(0, -.25);
  27. glVertex2d(CLIP, -CLIP);
  28. glVertex2d(.25, 0);
  29. glVertex2d(CLIP, CLIP);
  30. glEnd();
  31. glBegin(GL_POLYGON);
  32. glVertex2d(0, .25);
  33. glVertex2d(0, CLIP);
  34. glVertex2d(-CLIP, CLIP);
  35. glVertex2d(-CLIP, 0);
  36. glVertex2d(-.25, 0);
  37. glEnd();
  38. glBegin(GL_POLYGON);
  39. glVertex2d(-.25, 0);
  40. glVertex2d(-CLIP, 0);
  41. glVertex2d(-CLIP, -CLIP);
  42. glVertex2d(0, -CLIP);
  43. glVertex2d(0, -.25);
  44. glEnd();
  45. glBegin(GL_POLYGON);
  46. glVertex2d(0, -.25);
  47. glVertex2d(0, -CLIP);
  48. glVertex2d(CLIP, -CLIP);
  49. glVertex2d(CLIP, 0);
  50. glVertex2d(.25, 0);
  51. glEnd();
  52. glBegin(GL_POLYGON);
  53. glVertex2d(.25, 0);
  54. glVertex2d(CLIP, 0);
  55. glVertex2d(CLIP, CLIP);
  56. glVertex2d(0, CLIP);
  57. glVertex2d(0, .25);
  58. glEnd();
  59. if (fDouble)
  60. {
  61. auxSwapBuffers();
  62. }
  63. else
  64. {
  65. glFinish();
  66. }
  67. }
  68. void TestClip(void)
  69. {
  70. static GLboolean done = GL_FALSE;
  71. float eps, old;
  72. if (done)
  73. {
  74. return;
  75. }
  76. eps = .0001f;
  77. old = .0f;
  78. while (nIter-- > 0 && eps != old)
  79. {
  80. printf("TestClip %f\n", eps);
  81. clip_val = CLIP_CENTER+eps;
  82. Draw();
  83. clip_val = CLIP_CENTER-eps;
  84. Draw();
  85. old = eps;
  86. eps /= 10;
  87. }
  88. done = GL_TRUE;
  89. }
  90. void Nothing(void)
  91. {
  92. }
  93. void __cdecl main(int argc, char **argv)
  94. {
  95. GLenum mode;
  96. while (--argc > 0)
  97. {
  98. argv++;
  99. if (!strcmp(*argv, "-db"))
  100. {
  101. fDouble = TRUE;
  102. }
  103. else if (!strcmp(*argv, "-it"))
  104. {
  105. argv++;
  106. argc--;
  107. sscanf(*argv, "%d", &nIter);
  108. }
  109. }
  110. auxInitPosition(5, 5, WIDTH, HEIGHT);
  111. mode = AUX_RGB | AUX_DEPTH16;
  112. if (fDouble)
  113. {
  114. mode |= AUX_DOUBLE;
  115. }
  116. else
  117. {
  118. mode |= AUX_SINGLE;
  119. }
  120. auxInitDisplayMode(mode);
  121. auxInitWindow("OpenGL Line Clipping Test");
  122. glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  123. glClear(GL_COLOR_BUFFER_BIT);
  124. auxIdleFunc(TestClip);
  125. auxMainLoop(Nothing);
  126. }