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.

330 lines
5.2 KiB

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <math.h>
  4. #include <string.h>
  5. #include <windows.h>
  6. #include <gl\gl.h>
  7. #include <gl\glu.h>
  8. #include <gl\glaux.h>
  9. #define PI 3.14159265358979323846
  10. #define WIDTH 800
  11. #define HEIGHT 600
  12. GLfloat xr = 0.0f;
  13. GLfloat yr = 0.0f;
  14. GLfloat intensity = 0.1f;
  15. #define DRAW_TEAPOT 0x00000001
  16. #define DRAW_TORUS 0x00000002
  17. #define DRAW_SPHERE 0x00000004
  18. #define DRAW_GRID 0x00000008
  19. #define DRAW_CIRCLE 0x00000010
  20. #define DRAW_SINE 0x00000020
  21. DWORD dwDraw = 0xffffffff;
  22. BOOL fSingle = FALSE;
  23. BOOL fClipViewport = FALSE;
  24. BOOL fSmooth = FALSE;
  25. BOOL fPause = FALSE;
  26. BOOL fLargeView = FALSE;
  27. BOOL fLargeZ = FALSE;
  28. BOOL fColor = TRUE;
  29. int line_width = 1;
  30. int steps = 20;
  31. void Init(void)
  32. {
  33. double xyf, zf;
  34. xyf = fLargeView ? 2.0 : 1.0;
  35. zf = fLargeZ ? 2.0 : 1.0;
  36. glMatrixMode(GL_PROJECTION);
  37. glLoadIdentity();
  38. glOrtho(-xyf, xyf, -xyf, xyf, -zf, zf);
  39. glMatrixMode(GL_MODELVIEW);
  40. glShadeModel(fSmooth ? GL_SMOOTH : GL_FLAT);
  41. glLineWidth((GLfloat)line_width);
  42. }
  43. void Redraw(void)
  44. {
  45. DWORD ms;
  46. int i;
  47. float x1, y1, dx1, dy1;
  48. float x2, y2, dx2, dy2;
  49. float col, dcol;
  50. float ang, dang;
  51. ms = GetTickCount();
  52. glClear(GL_COLOR_BUFFER_BIT);
  53. glLoadIdentity();
  54. glRotatef(xr, 1.0f, 0.0f, 0.0f);
  55. glRotatef(yr, 0.0f, 1.0f, 0.0f);
  56. if (fColor)
  57. {
  58. glColor3f(intensity, 0.0f, 0.0f);
  59. }
  60. if (dwDraw & DRAW_SPHERE)
  61. {
  62. auxWireSphere(1.0);
  63. }
  64. if (dwDraw & DRAW_TORUS)
  65. {
  66. auxWireTorus(0.5, 1.0);
  67. }
  68. if (dwDraw & DRAW_TEAPOT)
  69. {
  70. auxWireTeapot(1.0);
  71. }
  72. if (dwDraw & DRAW_GRID)
  73. {
  74. x1 = -2.0f;
  75. y1 = 0.0f;
  76. dx1 = -x1/(steps-1);
  77. dy1 = 2.0f/(steps-1);
  78. x2 = -2.0f;
  79. y2 = 0.0f;
  80. dx2 = -x2/(steps-1);
  81. dy2 = -2.0f/(steps-1);
  82. col = 0.5f;
  83. dcol = 0.5f/(steps-1);
  84. glBegin(GL_LINES);
  85. for (i = 0; i < steps; i++)
  86. {
  87. if (fColor)
  88. {
  89. glColor3f(col, 0.0f, 0.0f);
  90. }
  91. glVertex2f(x1, y1);
  92. if (fColor)
  93. {
  94. glColor3f(0.0f, col, 0.0f);
  95. }
  96. glVertex2f(x1+2.0f, y1-2.0f);
  97. if (fColor)
  98. {
  99. glColor3f(1.5f-col, 0.0f, 0.0f);
  100. }
  101. glVertex2f(x2, y2);
  102. if (fColor)
  103. {
  104. glColor3f(0.0f, 1.5f-col, 0.0f);
  105. }
  106. glVertex2f(x2+2.0f, y2+2.0f);
  107. x1 += dx1;
  108. y1 += dy1;
  109. x2 += dx2;
  110. y2 += dy2;
  111. col += dcol;
  112. }
  113. glEnd();
  114. }
  115. if (dwDraw & DRAW_CIRCLE)
  116. {
  117. if (fColor)
  118. {
  119. glColor3f(0.0f, intensity, 0.0f);
  120. }
  121. ang = 0.0f;
  122. dang = (float)((PI*2.0)/steps);
  123. glBegin(GL_LINE_LOOP);
  124. for (i = 0; i < steps; i++)
  125. {
  126. x1 = (float)(cos(ang)*1.5);
  127. y1 = (float)(sin(ang)*1.5);
  128. glVertex2f(x1, y1);
  129. ang += dang;
  130. }
  131. glEnd();
  132. }
  133. if (dwDraw & DRAW_SINE)
  134. {
  135. if (fColor)
  136. {
  137. glColor3f(0.0f, 0.0f, intensity);
  138. }
  139. ang = 0.0f;
  140. dang = (float)((PI*2.0)/(steps-1));
  141. x1 = -1.5f;
  142. dx1 = 3.0f/(steps-1);
  143. glBegin(GL_LINE_STRIP);
  144. for (i = 0; i < steps; i++)
  145. {
  146. y1 = (float)(sin(ang)*1.5);
  147. glVertex2f(x1, y1);
  148. ang += dang;
  149. x1 += dx1;
  150. }
  151. glEnd();
  152. }
  153. glFinish();
  154. ms = GetTickCount()-ms;
  155. printf("%d ms\n", ms);
  156. if (!fSingle)
  157. {
  158. auxSwapBuffers();
  159. }
  160. }
  161. void Reshape(GLsizei w, GLsizei h)
  162. {
  163. if (!fClipViewport)
  164. {
  165. glViewport(0, 0, w, h);
  166. }
  167. else
  168. {
  169. glViewport(WIDTH, 0, w, h);
  170. }
  171. }
  172. void Step(void)
  173. {
  174. xr += 2.0f;
  175. yr += 2.0f;
  176. intensity += 0.1f;
  177. if (intensity > 1.0f)
  178. {
  179. intensity = 0.1f;
  180. }
  181. Redraw();
  182. }
  183. void KeySpace(void)
  184. {
  185. Step();
  186. }
  187. char *draw_names[] =
  188. {
  189. "teapot",
  190. "torus",
  191. "sphere",
  192. "grid",
  193. "circle",
  194. "sine"
  195. };
  196. #define DRAW_COUNT (sizeof(draw_names)/sizeof(draw_names[0]))
  197. DWORD DrawBit(char *name)
  198. {
  199. int i;
  200. DWORD bit;
  201. bit = 1;
  202. for (i = 0; i < DRAW_COUNT; i++)
  203. {
  204. if (!strcmp(name, draw_names[i]))
  205. {
  206. return bit;
  207. }
  208. bit <<= 1;
  209. }
  210. if (strlen(name) == 0)
  211. {
  212. return 0xffffffff;
  213. }
  214. else
  215. {
  216. printf("No draw option '%s'\n", name);
  217. return 0;
  218. }
  219. }
  220. void __cdecl main(int argc, char **argv)
  221. {
  222. int mode;
  223. while (--argc > 0)
  224. {
  225. argv++;
  226. if (!strcmp(*argv, "-sb"))
  227. {
  228. fSingle = TRUE;
  229. }
  230. else if (!strcmp(*argv, "-clip"))
  231. {
  232. fClipViewport = TRUE;
  233. }
  234. else if (!strncmp(*argv, "-lw", 3))
  235. {
  236. sscanf(*argv+3, "%d", &line_width);
  237. }
  238. else if (!strcmp(*argv, "-smooth"))
  239. {
  240. fSmooth = TRUE;
  241. }
  242. else if (!strcmp(*argv, "-pause"))
  243. {
  244. fPause = TRUE;
  245. }
  246. else if (!strncmp(*argv, "-draw", 5))
  247. {
  248. dwDraw &= ~DrawBit(*argv+5);
  249. }
  250. else if (!strncmp(*argv, "+draw", 5))
  251. {
  252. dwDraw |= DrawBit(*argv+5);
  253. }
  254. else if (!strcmp(*argv, "-nocolor"))
  255. {
  256. fColor = FALSE;
  257. }
  258. else if (!strcmp(*argv, "-largeview"))
  259. {
  260. fLargeView = TRUE;
  261. }
  262. else if (!strcmp(*argv, "-largez"))
  263. {
  264. fLargeZ = TRUE;
  265. }
  266. }
  267. auxInitPosition(10, 10, WIDTH, HEIGHT);
  268. mode = AUX_RGB | AUX_DEPTH16;
  269. if (!fSingle)
  270. {
  271. mode |= AUX_DOUBLE;
  272. }
  273. auxInitDisplayMode(mode);
  274. auxInitWindow("Wireframe Performance Test");
  275. auxReshapeFunc(Reshape);
  276. if (!fPause)
  277. {
  278. auxIdleFunc(Step);
  279. }
  280. auxKeyFunc(AUX_SPACE, KeySpace);
  281. Init();
  282. auxMainLoop(Redraw);
  283. }