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.

845 lines
15 KiB

  1. /*
  2. * (c) Copyright 1993, Silicon Graphics, Inc.
  3. * ALL RIGHTS RESERVED
  4. * Permission to use, copy, modify, and distribute this software for
  5. * any purpose and without fee is hereby granted, provided that the above
  6. * copyright notice appear in all copies and that both the copyright notice
  7. * and this permission notice appear in supporting documentation, and that
  8. * the name of Silicon Graphics, Inc. not be used in advertising
  9. * or publicity pertaining to distribution of the software without specific,
  10. * written prior permission.
  11. *
  12. * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  13. * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  14. * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  15. * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
  16. * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  17. * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  18. * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  19. * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  20. * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
  21. * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  22. * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  23. * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  24. *
  25. * US Government Users Restricted Rights
  26. * Use, duplication, or disclosure by the Government is subject to
  27. * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  28. * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  29. * clause at DFARS 252.227-7013 and/or in similar or successor
  30. * clauses in the FAR or the DOD or NASA FAR Supplement.
  31. * Unpublished-- rights reserved under the copyright laws of the
  32. * United States. Contractor/manufacturer is Silicon Graphics,
  33. * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
  34. *
  35. * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  36. */
  37. #include <stdio.h>
  38. #include <string.h>
  39. #include <sys/types.h>
  40. #include <sys/stat.h>
  41. #include <fcntl.h>
  42. #include <math.h>
  43. #include <time.h>
  44. #include <sys\types.h>
  45. #include <sys\timeb.h>
  46. #include <stdlib.h>
  47. #include <ddraw.h>
  48. #include "tk.h"
  49. #pragma warning(disable:4244)
  50. GLenum doubleBuffer, directRender;
  51. LPDIRECTDRAWSURFACE pddsTex;
  52. DDSURFACEDESC ddsdTex;
  53. #define WWIDTH 300
  54. #define WHEIGHT 300
  55. #define TWIDTH 256
  56. #define THEIGHT 256
  57. #define TRAIL_X 1
  58. #define TRAIL_Y 1
  59. #define TRAIL_WIDTH (TWIDTH-2*TRAIL_X)
  60. #define TRAIL_HEIGHT (THEIGHT-2*TRAIL_Y)
  61. #define TRAIL_SPEED (TRAIL_WIDTH/16)
  62. #define TRAIL_MIN_SPEED 2
  63. #define TRAIL_RAND_SPEED() ((rand() % TRAIL_SPEED)+TRAIL_MIN_SPEED)
  64. #define TRAIL 16
  65. #define NEXT_TRAIL_IDX(idx) (((idx)+1) & (TRAIL-1))
  66. POINT trail[TRAIL][2];
  67. POINT vel[2];
  68. int trail_idx = 0;
  69. double trail_hue = 0.0;
  70. #define HUE_STEP 1.0
  71. #define NEXT_TRAIL_HUE(hue) \
  72. ((hue) < (360.0-HUE_STEP) ? (hue)+HUE_STEP : (hue)+HUE_STEP-360.0)
  73. float *minFilter, *magFilter, *sWrapMode, *tWrapMode;
  74. float decal[] = {GL_DECAL};
  75. float modulate[] = {GL_MODULATE};
  76. float repeat[] = {GL_REPEAT};
  77. float clamp[] = {GL_CLAMP};
  78. float nr[] = {GL_NEAREST};
  79. float ln[] = {GL_LINEAR};
  80. float nr_mipmap_nr[] = {GL_NEAREST_MIPMAP_NEAREST};
  81. float nr_mipmap_ln[] = {GL_NEAREST_MIPMAP_LINEAR};
  82. float ln_mipmap_nr[] = {GL_LINEAR_MIPMAP_NEAREST};
  83. float ln_mipmap_ln[] = {GL_LINEAR_MIPMAP_LINEAR};
  84. GLint sphereMap[] = {GL_SPHERE_MAP};
  85. GLboolean displayFrameRate = GL_FALSE;
  86. GLboolean animate = GL_TRUE;
  87. GLboolean spin = GL_TRUE;
  88. GLboolean showSphere = GL_FALSE;
  89. GLint frames, curFrame = 0, nextFrame = 0;
  90. GLint frameCount = 0;
  91. GLenum doDither = GL_TRUE;
  92. GLenum doSphere = GL_FALSE;
  93. float xRotation = 0.0, yRotation = 0.0, zTranslate = -3.125;
  94. GLint cube;
  95. float c[6][4][3] = {
  96. {
  97. {
  98. 1.0, 1.0, -1.0
  99. },
  100. {
  101. -1.0, 1.0, -1.0
  102. },
  103. {
  104. -1.0, -1.0, -1.0
  105. },
  106. {
  107. 1.0, -1.0, -1.0
  108. }
  109. },
  110. {
  111. {
  112. 1.0, 1.0, 1.0
  113. },
  114. {
  115. 1.0, 1.0, -1.0
  116. },
  117. {
  118. 1.0, -1.0, -1.0
  119. },
  120. {
  121. 1.0, -1.0, 1.0
  122. }
  123. },
  124. {
  125. {
  126. -1.0, 1.0, 1.0
  127. },
  128. {
  129. 1.0, 1.0, 1.0
  130. },
  131. {
  132. 1.0, -1.0, 1.0
  133. },
  134. {
  135. -1.0, -1.0, 1.0
  136. }
  137. },
  138. {
  139. {
  140. -1.0, 1.0, -1.0
  141. },
  142. {
  143. -1.0, 1.0, 1.0
  144. },
  145. {
  146. -1.0, -1.0, 1.0
  147. },
  148. {
  149. -1.0, -1.0, -1.0
  150. }
  151. },
  152. {
  153. {
  154. -1.0, 1.0, 1.0
  155. },
  156. {
  157. -1.0, 1.0, -1.0
  158. },
  159. {
  160. 1.0, 1.0, -1.0
  161. },
  162. {
  163. 1.0, 1.0, 1.0
  164. }
  165. },
  166. {
  167. {
  168. -1.0, -1.0, -1.0
  169. },
  170. {
  171. -1.0, -1.0, 1.0
  172. },
  173. {
  174. 1.0, -1.0, 1.0
  175. },
  176. {
  177. 1.0, -1.0, -1.0
  178. }
  179. }
  180. };
  181. static float n[6][3] = {
  182. {
  183. 0.0, 0.0, -1.0
  184. },
  185. {
  186. 1.0, 0.0, 0.0
  187. },
  188. {
  189. 0.0, 0.0, 1.0
  190. },
  191. {
  192. -1.0, 0.0, 0.0
  193. },
  194. {
  195. 0.0, 1.0, 0.0
  196. },
  197. {
  198. 0.0, -1.0, 0.0
  199. }
  200. };
  201. #if 0
  202. static float t[6][4][2] = {
  203. {
  204. {
  205. 1.1, 1.1
  206. },
  207. {
  208. -0.1, 1.1
  209. },
  210. {
  211. -0.1, -0.1
  212. },
  213. {
  214. 1.1, -0.1
  215. }
  216. },
  217. {
  218. {
  219. 1.1, 1.1
  220. },
  221. {
  222. -0.1, 1.1
  223. },
  224. {
  225. -0.1, -0.1
  226. },
  227. {
  228. 1.1, -0.1
  229. }
  230. },
  231. {
  232. {
  233. -0.1, 1.1
  234. },
  235. {
  236. 1.1, 1.1
  237. },
  238. {
  239. 1.1, -0.1
  240. },
  241. {
  242. -0.1, -0.1
  243. }
  244. },
  245. {
  246. {
  247. 1.1, 1.1
  248. },
  249. {
  250. -0.1, 1.1
  251. },
  252. {
  253. -0.1, -0.1
  254. },
  255. {
  256. 1.1, -0.1
  257. }
  258. },
  259. {
  260. {
  261. 1.1, 1.1
  262. },
  263. {
  264. -0.1, 1.1
  265. },
  266. {
  267. -0.1, -0.1
  268. },
  269. {
  270. 1.1, -0.1
  271. }
  272. },
  273. {
  274. {
  275. 1.1, 1.1
  276. },
  277. {
  278. -0.1, 1.1
  279. },
  280. {
  281. -0.1, -0.1
  282. },
  283. {
  284. 1.1, -0.1
  285. }
  286. },
  287. };
  288. #else
  289. static float t[6][4][2] = {
  290. {
  291. {
  292. 1.0, 1.0
  293. },
  294. {
  295. -0.0, 1.0
  296. },
  297. {
  298. -0.0, -0.0
  299. },
  300. {
  301. 1.0, -0.0
  302. }
  303. },
  304. {
  305. {
  306. 1.0, 1.0
  307. },
  308. {
  309. -0.0, 1.0
  310. },
  311. {
  312. -0.0, -0.0
  313. },
  314. {
  315. 1.0, -0.0
  316. }
  317. },
  318. {
  319. {
  320. -0.0, 1.0
  321. },
  322. {
  323. 1.0, 1.0
  324. },
  325. {
  326. 1.0, -0.0
  327. },
  328. {
  329. -0.0, -0.0
  330. }
  331. },
  332. {
  333. {
  334. 1.0, 1.0
  335. },
  336. {
  337. -0.0, 1.0
  338. },
  339. {
  340. -0.0, -0.0
  341. },
  342. {
  343. 1.0, -0.0
  344. }
  345. },
  346. {
  347. {
  348. 1.0, 1.0
  349. },
  350. {
  351. -0.0, 1.0
  352. },
  353. {
  354. -0.0, -0.0
  355. },
  356. {
  357. 1.0, -0.0
  358. }
  359. },
  360. {
  361. {
  362. 1.0, 1.0
  363. },
  364. {
  365. -0.0, 1.0
  366. },
  367. {
  368. -0.0, -0.0
  369. },
  370. {
  371. 1.0, -0.0
  372. }
  373. },
  374. };
  375. #endif
  376. static void Animate(void);
  377. void SolidSphere (GLdouble radius)
  378. {
  379. GLUquadricObj *quadObj;
  380. static GLuint displayList = 0;
  381. if (displayList == 0) {
  382. displayList = glGenLists(1);
  383. glNewList(displayList, GL_COMPILE_AND_EXECUTE);
  384. quadObj = gluNewQuadric ();
  385. gluQuadricDrawStyle (quadObj, GLU_FILL);
  386. gluQuadricNormals (quadObj, GLU_SMOOTH);
  387. gluQuadricTexture (quadObj, GL_TRUE);
  388. gluSphere (quadObj, radius, 16, 16);
  389. glEndList();
  390. }
  391. else {
  392. glCallList(displayList);
  393. }
  394. }
  395. COLORREF HueToRgb(double hue)
  396. {
  397. int hex;
  398. double frac;
  399. BYTE v1, v2, v3;
  400. hue /= 60.0;
  401. hex = (int)hue;
  402. frac = hue-hex;
  403. v1 = 0;
  404. v2 = (BYTE)((1-frac)*255);
  405. v3 = (BYTE)(frac*255);
  406. switch(hex)
  407. {
  408. case 0:
  409. return RGB(255, v3, v1);
  410. case 1:
  411. return RGB(v2, 255, v1);
  412. case 2:
  413. return RGB(v1, 255, v3);
  414. case 3:
  415. return RGB(v1, v2, 255);
  416. case 4:
  417. return RGB(v3, v1, 255);
  418. default:
  419. return RGB(255, v1, v2);
  420. }
  421. }
  422. static void BuildCube(void)
  423. {
  424. GLint i;
  425. glNewList(cube, GL_COMPILE);
  426. for (i = 0; i < 6; i++) {
  427. glBegin(GL_POLYGON);
  428. glNormal3fv(n[i]); glTexCoord2fv(t[i][0]); glVertex3fv(c[i][0]);
  429. glNormal3fv(n[i]); glTexCoord2fv(t[i][1]); glVertex3fv(c[i][1]);
  430. glNormal3fv(n[i]); glTexCoord2fv(t[i][2]); glVertex3fv(c[i][2]);
  431. glNormal3fv(n[i]); glTexCoord2fv(t[i][3]); glVertex3fv(c[i][3]);
  432. glEnd();
  433. }
  434. glEndList();
  435. }
  436. static void BuildLists(void)
  437. {
  438. cube = glGenLists(1);
  439. BuildCube();
  440. }
  441. BOOL WINAPI texCallback(LPDDSURFACEDESC pddsd, LPVOID pv)
  442. {
  443. if (pddsd->ddpfPixelFormat.dwFlags == DDPF_RGB)
  444. {
  445. ddsdTex = *pddsd;
  446. return FALSE;
  447. }
  448. else
  449. {
  450. return TRUE;
  451. }
  452. }
  453. void CreateTex(void)
  454. {
  455. LPDIRECTDRAW pdd;
  456. HDC hdc;
  457. if (!wglEnumTextureFormats(texCallback, NULL))
  458. {
  459. printf("wglEnumTextureFormats failed, %d\n", GetLastError());
  460. tkQuit();
  461. }
  462. if (DirectDrawCreate(NULL, &pdd, NULL) != DD_OK)
  463. {
  464. tkQuit();
  465. }
  466. if (pdd->lpVtbl->SetCooperativeLevel(pdd, NULL, DDSCL_NORMAL) != DD_OK)
  467. {
  468. tkQuit();
  469. }
  470. ddsdTex.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT;
  471. ddsdTex.dwWidth = TWIDTH;
  472. ddsdTex.dwHeight = THEIGHT;
  473. ddsdTex.ddsCaps.dwCaps &= ~DDSCAPS_MIPMAP;
  474. if (pdd->lpVtbl->CreateSurface(pdd, &ddsdTex, &pddsTex, NULL) != DD_OK)
  475. {
  476. tkQuit();
  477. }
  478. if (pddsTex->lpVtbl->GetDC(pddsTex, &hdc) != DD_OK)
  479. {
  480. tkQuit();
  481. }
  482. SelectObject(hdc, GetStockObject(BLACK_BRUSH));
  483. SelectObject(hdc, GetStockObject(WHITE_PEN));
  484. Rectangle(hdc, 0, 0, TWIDTH, THEIGHT);
  485. pddsTex->lpVtbl->ReleaseDC(pddsTex, hdc);
  486. }
  487. static void Init(void)
  488. {
  489. CreateTex();
  490. srand(time(NULL));
  491. trail[0][0].x = (rand() % TRAIL_WIDTH)+TRAIL_X;
  492. trail[0][0].y = (rand() % TRAIL_HEIGHT)+TRAIL_Y;
  493. trail[0][1].x = (rand() % TRAIL_WIDTH)+TRAIL_X;
  494. trail[0][1].y = (rand() % TRAIL_HEIGHT)+TRAIL_Y;
  495. vel[0].x = TRAIL_RAND_SPEED();
  496. vel[0].y = TRAIL_RAND_SPEED();
  497. vel[1].x = TRAIL_RAND_SPEED();
  498. vel[1].y = TRAIL_RAND_SPEED();
  499. wglBindDirectDrawTexture(pddsTex);
  500. glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, decal);
  501. glEnable(GL_TEXTURE_2D);
  502. glFrontFace(GL_CCW);
  503. glCullFace(GL_FRONT);
  504. glEnable(GL_CULL_FACE);
  505. BuildLists();
  506. glClearColor(0.0, 0.0, 0.0, 0.0);
  507. magFilter = nr;
  508. minFilter = nr;
  509. sWrapMode = repeat;
  510. tWrapMode = repeat;
  511. glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
  512. }
  513. static void Reshape(int width, int height)
  514. {
  515. glViewport(0, 0, (GLint)width, (GLint)height);
  516. glMatrixMode(GL_PROJECTION);
  517. glLoadIdentity();
  518. gluPerspective(90.0, 1.0, 0.01, 1000);
  519. glMatrixMode(GL_MODELVIEW);
  520. }
  521. static GLenum Key(int key, GLenum mask)
  522. {
  523. switch (key) {
  524. case TK_ESCAPE:
  525. tkQuit();
  526. case TK_SPACE:
  527. if (animate)
  528. {
  529. tkIdleFunc(NULL);
  530. }
  531. else
  532. {
  533. tkIdleFunc(Animate);
  534. }
  535. animate = !animate;
  536. break;
  537. case TK_n:
  538. spin = !spin;
  539. break;
  540. case TK_p:
  541. showSphere = !showSphere;
  542. break;
  543. case TK_LEFT:
  544. yRotation -= 0.5;
  545. break;
  546. case TK_RIGHT:
  547. yRotation += 0.5;
  548. break;
  549. case TK_UP:
  550. xRotation -= 0.5;
  551. break;
  552. case TK_DOWN:
  553. xRotation += 0.5;
  554. break;
  555. case TK_f:
  556. displayFrameRate = !displayFrameRate;
  557. frameCount = 0;
  558. break;
  559. case TK_d:
  560. doDither = !doDither;
  561. (doDither) ? glEnable(GL_DITHER) : glDisable(GL_DITHER);
  562. break;
  563. case TK_T:
  564. zTranslate += 0.25;
  565. break;
  566. case TK_t:
  567. zTranslate -= 0.25;
  568. break;
  569. case TK_s:
  570. doSphere = !doSphere;
  571. if (doSphere) {
  572. glTexGeniv(GL_S, GL_TEXTURE_GEN_MODE, sphereMap);
  573. glTexGeniv(GL_T, GL_TEXTURE_GEN_MODE, sphereMap);
  574. glEnable(GL_TEXTURE_GEN_S);
  575. glEnable(GL_TEXTURE_GEN_T);
  576. } else {
  577. glDisable(GL_TEXTURE_GEN_S);
  578. glDisable(GL_TEXTURE_GEN_T);
  579. }
  580. break;
  581. case TK_0:
  582. magFilter = nr;
  583. break;
  584. case TK_1:
  585. magFilter = ln;
  586. break;
  587. case TK_2:
  588. minFilter = nr;
  589. break;
  590. case TK_3:
  591. minFilter = ln;
  592. break;
  593. case TK_4:
  594. minFilter = nr_mipmap_nr;
  595. break;
  596. case TK_5:
  597. minFilter = nr_mipmap_ln;
  598. break;
  599. case TK_6:
  600. minFilter = ln_mipmap_nr;
  601. break;
  602. case TK_7:
  603. minFilter = ln_mipmap_ln;
  604. break;
  605. default:
  606. return GL_FALSE;
  607. }
  608. return GL_TRUE;
  609. }
  610. static void Draw(void)
  611. {
  612. glClear(GL_COLOR_BUFFER_BIT);
  613. glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, sWrapMode);
  614. glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, tWrapMode);
  615. glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter);
  616. glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter);
  617. glPushMatrix();
  618. glTranslatef(0.0, 0.0, zTranslate);
  619. glRotatef(xRotation, 1, 0, 0);
  620. glRotatef(yRotation, 0, 1, 0);
  621. if (showSphere)
  622. {
  623. SolidSphere(1);
  624. }
  625. else
  626. {
  627. glCallList(cube);
  628. }
  629. glPopMatrix();
  630. glFlush();
  631. if (doubleBuffer) {
  632. tkSwapBuffers();
  633. }
  634. }
  635. static GLenum Args(int argc, char **argv)
  636. {
  637. GLint i;
  638. doubleBuffer = GL_FALSE;
  639. directRender = GL_FALSE;
  640. for (i = 1; i < argc; i++) {
  641. if (strcmp(argv[i], "-sb") == 0) {
  642. doubleBuffer = GL_FALSE;
  643. } else if (strcmp(argv[i], "-db") == 0) {
  644. doubleBuffer = GL_TRUE;
  645. } else if (strcmp(argv[i], "-dr") == 0) {
  646. directRender = GL_TRUE;
  647. } else if (strcmp(argv[i], "-ir") == 0) {
  648. directRender = GL_FALSE;
  649. } else {
  650. printf("%s (Bad option).\n", argv[i]);
  651. return GL_FALSE;
  652. }
  653. }
  654. return GL_TRUE;
  655. }
  656. void UpdateTex(void)
  657. {
  658. HDC hdc;
  659. int i;
  660. int idx;
  661. HPEN hpen;
  662. if (pddsTex->lpVtbl->GetDC(pddsTex, &hdc) != DD_OK)
  663. {
  664. tkQuit();
  665. }
  666. idx = NEXT_TRAIL_IDX(trail_idx);
  667. // Erase oldest trail line
  668. SelectObject(hdc, GetStockObject(BLACK_PEN));
  669. MoveToEx(hdc, trail[idx][0].x, trail[idx][0].y, NULL);
  670. LineTo(hdc, trail[idx][1].x, trail[idx][1].y);
  671. // Update points
  672. for (i = 0; i < 2; i++)
  673. {
  674. trail[idx][i].x = trail[trail_idx][i].x+vel[i].x;
  675. if (trail[idx][i].x < TRAIL_X)
  676. {
  677. trail[idx][i].x = TRAIL_X;
  678. vel[i].x = TRAIL_RAND_SPEED();
  679. }
  680. else if (trail[idx][i].x >= TRAIL_X+TRAIL_WIDTH)
  681. {
  682. trail[idx][i].x = TRAIL_X+TRAIL_WIDTH-1;
  683. vel[i].x = -TRAIL_RAND_SPEED();
  684. }
  685. trail[idx][i].y = trail[trail_idx][i].y+vel[i].y;
  686. if (trail[idx][i].y < TRAIL_Y)
  687. {
  688. trail[idx][i].y = TRAIL_Y;
  689. vel[i].y = TRAIL_RAND_SPEED();
  690. }
  691. else if (trail[idx][i].y >= TRAIL_Y+TRAIL_HEIGHT)
  692. {
  693. trail[idx][i].y = TRAIL_Y+TRAIL_HEIGHT-1;
  694. vel[i].y = -TRAIL_RAND_SPEED();
  695. }
  696. }
  697. // Draw newest line
  698. hpen = CreatePen(PS_SOLID, 0, HueToRgb(trail_hue));
  699. SelectObject(hdc, hpen);
  700. MoveToEx(hdc, trail[idx][0].x, trail[idx][0].y, NULL);
  701. LineTo(hdc, trail[idx][1].x, trail[idx][1].y);
  702. SelectObject(hdc, GetStockObject(WHITE_PEN));
  703. DeleteObject(hpen);
  704. trail_idx = idx;
  705. trail_hue = NEXT_TRAIL_HUE(trail_hue);
  706. pddsTex->lpVtbl->ReleaseDC(pddsTex, hdc);
  707. }
  708. static void Animate(void)
  709. {
  710. static struct _timeb thisTime, baseTime;
  711. double elapsed, frameRate, deltat;
  712. if (curFrame++ >= 10) {
  713. if( !frameCount ) {
  714. _ftime( &baseTime );
  715. }
  716. else {
  717. if( displayFrameRate ) {
  718. _ftime( &thisTime );
  719. elapsed = thisTime.time + thisTime.millitm/1000.0 -
  720. (baseTime.time + baseTime.millitm/1000.0);
  721. if( elapsed == 0.0 )
  722. printf( "Frame rate = unknown\n" );
  723. else {
  724. frameRate = frameCount / elapsed;
  725. printf( "Frame rate = %5.2f fps\n", frameRate );
  726. }
  727. }
  728. }
  729. frameCount += 10;
  730. curFrame = 0;
  731. }
  732. UpdateTex();
  733. Draw();
  734. if (spin)
  735. {
  736. xRotation += 10.0;
  737. yRotation += 10.0;
  738. }
  739. }
  740. void __cdecl main(int argc, char **argv)
  741. {
  742. GLenum type;
  743. if (Args(argc, argv) == GL_FALSE) {
  744. tkQuit();
  745. }
  746. tkInitPosition(0, 0, WWIDTH, WHEIGHT);
  747. type = TK_RGB;
  748. type |= (doubleBuffer) ? TK_DOUBLE : TK_SINGLE;
  749. type |= (directRender) ? TK_DIRECT : TK_INDIRECT;
  750. tkInitDisplayMode(type);
  751. if (tkInitWindow("Texture Test") == GL_FALSE) {
  752. tkQuit();
  753. }
  754. Init();
  755. tkExposeFunc(Reshape);
  756. tkReshapeFunc(Reshape);
  757. tkKeyDownFunc(Key);
  758. tkDisplayFunc(Draw);
  759. if (animate)
  760. {
  761. tkIdleFunc(Animate);
  762. }
  763. tkExec();
  764. }