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.

215 lines
3.8 KiB

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <math.h>
  4. #include <string.h>
  5. #include <time.h>
  6. #include <windows.h>
  7. #include <gl\gl.h>
  8. #include <gl\glu.h>
  9. #include <gl\glaux.h>
  10. #define PI ((float)3.14159265358979323846)
  11. #define WIDTH 512
  12. #define HEIGHT 512
  13. BOOL fSingle = FALSE;
  14. BOOL fRotate = FALSE;
  15. BOOL fColor = FALSE;
  16. BOOL fNormal = FALSE;
  17. BOOL fTexture = FALSE;
  18. DWORD dwTotalMillis = 0;
  19. int iTotalPoints = 0;
  20. #define DEF_PRIM_POINTS 250
  21. #define DEF_PRIMS 250
  22. int iPrims = DEF_PRIMS;
  23. int iPrimPoints = DEF_PRIM_POINTS;
  24. int iPoints = DEF_PRIMS*DEF_PRIM_POINTS;
  25. float fRotAngle = 0.0f;
  26. #define MAX_COLOR (3*3)
  27. float afColors[MAX_COLOR] =
  28. {
  29. 1.0f, 0.0f, 0.0f,
  30. 0.0f, 1.0f, 0.0f,
  31. 0.0f, 0.0f, 1.0f
  32. };
  33. float *pfCurColor;
  34. void Init(void)
  35. {
  36. glMatrixMode(GL_PROJECTION);
  37. glLoadIdentity();
  38. gluPerspective(45, 1, .01, 15);
  39. gluLookAt(0, 0, 3, 0, 0, 0, 0, 1, 0);
  40. glMatrixMode(GL_MODELVIEW);
  41. }
  42. void ResetTotals(void)
  43. {
  44. dwTotalMillis = 0;
  45. iTotalPoints = 0;
  46. }
  47. void Redraw(void)
  48. {
  49. DWORD dwMillis;
  50. char szMsg[80];
  51. int iPt, iPrim;
  52. float fX, fY, fDx, fDy;
  53. dwMillis = GetTickCount();
  54. glClear(GL_COLOR_BUFFER_BIT);
  55. if (fRotate)
  56. {
  57. glLoadIdentity();
  58. glRotatef(fRotAngle, 0.0f, 0.0f, 1.0f);
  59. fRotAngle += 2.0f;
  60. }
  61. fDx = 2.0f/(iPrimPoints-1);
  62. fDy = 2.0f/(iPrims-1);
  63. fY = -1.0f;
  64. pfCurColor = afColors;
  65. for (iPrim = 0; iPrim < iPrims; iPrim++)
  66. {
  67. fX = -1.0f;
  68. glBegin(GL_POINTS);
  69. for (iPt = 0; iPt < iPrimPoints; iPt++)
  70. {
  71. if (fColor)
  72. {
  73. glColor3fv(pfCurColor);
  74. pfCurColor += 3;
  75. if (pfCurColor >= afColors+MAX_COLOR)
  76. {
  77. pfCurColor = afColors;
  78. }
  79. }
  80. if (fNormal)
  81. {
  82. glNormal3f(0.0f, 0.0f, 1.0f);
  83. }
  84. if (fTexture)
  85. {
  86. glTexCoord2f(0.5f, 0.5f);
  87. }
  88. glVertex3f(fX, fY, 0.0f);
  89. fX += fDx;
  90. }
  91. glEnd();
  92. fY += fDy;
  93. }
  94. if (fSingle)
  95. {
  96. glFlush();
  97. }
  98. else
  99. {
  100. auxSwapBuffers();
  101. }
  102. dwMillis = GetTickCount()-dwMillis;
  103. dwTotalMillis += dwMillis;
  104. iTotalPoints += iPoints;
  105. if (dwTotalMillis > 1000)
  106. {
  107. sprintf(szMsg, "%.3lf pts/sec",
  108. (double)iTotalPoints*1000.0/dwTotalMillis);
  109. SetWindowText(auxGetHWND(), szMsg);
  110. ResetTotals();
  111. }
  112. }
  113. void Reshape(GLsizei w, GLsizei h)
  114. {
  115. glViewport(0, 0, w, h);
  116. }
  117. void Keyc(void)
  118. {
  119. ResetTotals();
  120. fColor = !fColor;
  121. }
  122. void Keyn(void)
  123. {
  124. ResetTotals();
  125. fNormal = !fNormal;
  126. }
  127. void KeyP(void)
  128. {
  129. int iv1[1];
  130. ResetTotals();
  131. glGetIntegerv(GL_CLIP_VOLUME_CLIPPING_HINT_EXT, &iv1[0]);
  132. if (iv1[0] == GL_FASTEST)
  133. {
  134. glHint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT, GL_DONT_CARE);
  135. }
  136. else
  137. {
  138. glHint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT, GL_FASTEST);
  139. }
  140. }
  141. void Keyt(void)
  142. {
  143. ResetTotals();
  144. fTexture = !fTexture;
  145. }
  146. void __cdecl main(int argc, char **argv)
  147. {
  148. GLenum eMode;
  149. while (--argc > 0)
  150. {
  151. argv++;
  152. if (!strcmp(*argv, "-sb"))
  153. {
  154. fSingle = TRUE;
  155. }
  156. else if (!strcmp(*argv, "-rotate"))
  157. {
  158. fRotate = TRUE;
  159. }
  160. }
  161. auxInitPosition(10, 10, WIDTH, HEIGHT);
  162. eMode = AUX_RGB;
  163. if (!fSingle)
  164. {
  165. eMode |= AUX_DOUBLE;
  166. }
  167. auxInitDisplayMode(eMode);
  168. auxInitWindow("Vertex API Timing");
  169. auxReshapeFunc(Reshape);
  170. auxIdleFunc(Redraw);
  171. auxKeyFunc(AUX_c, Keyc);
  172. auxKeyFunc(AUX_n, Keyn);
  173. auxKeyFunc(AUX_P, KeyP);
  174. auxKeyFunc(AUX_t, Keyt);
  175. Init();
  176. auxMainLoop(Redraw);
  177. }