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.

657 lines
17 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 <stdlib.h>
  40. #include <math.h>
  41. #include <time.h>
  42. #include <sys\types.h>
  43. #include <sys\timeb.h>
  44. #include "tk.h"
  45. #define PI 3.14159265358979323846
  46. #define GETCOORD(frame, x, y) (&(theMesh.coords[frame*theMesh.numCoords+(x)+(y)*(theMesh.widthX+1)]))
  47. #define GETFACET(frame, x, y) (&(theMesh.facets[frame*theMesh.numFacets+(x)+(y)*theMesh.widthX]))
  48. GLenum rgb, doubleBuffer, directRender, noSwap, noClear;
  49. GLint colorIndexes1[3];
  50. GLint colorIndexes2[3];
  51. GLenum clearMask = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT;
  52. GLenum smooth = GL_TRUE;
  53. GLenum lighting = GL_TRUE;
  54. GLenum depth = GL_TRUE;
  55. GLenum stepMode = GL_FALSE;
  56. GLenum spinMode = GL_FALSE;
  57. GLint contouring = 0;
  58. GLint widthX, widthY;
  59. GLint checkerSize;
  60. float height;
  61. GLint frames, curFrame = 0, nextFrame = 0;
  62. GLboolean displayFrameRate = GL_FALSE;
  63. static GLint frameCount = 0;
  64. struct facet {
  65. float color[3];
  66. float normal[3];
  67. };
  68. struct coord {
  69. float vertex[3];
  70. float normal[3];
  71. };
  72. struct mesh {
  73. GLint widthX, widthY;
  74. GLint numFacets;
  75. GLint numCoords;
  76. GLint frames;
  77. struct coord *coords;
  78. struct facet *facets;
  79. } theMesh;
  80. GLubyte contourTexture1[] = {
  81. 255, 255, 255, 255,
  82. 255, 255, 255, 255,
  83. 255, 255, 255, 255,
  84. 127, 127, 127, 127,
  85. };
  86. GLubyte contourTexture2[] = {
  87. 255, 255, 255, 255,
  88. 255, 127, 127, 127,
  89. 255, 127, 127, 127,
  90. 255, 127, 127, 127,
  91. };
  92. static void Animate(void)
  93. {
  94. struct coord *coord;
  95. struct facet *facet;
  96. float *lastColor;
  97. float *thisColor;
  98. GLint i, j;
  99. static struct _timeb thisTime, baseTime;
  100. double elapsed, frameRate, deltat;
  101. if (!noClear)
  102. {
  103. glClear(clearMask);
  104. }
  105. if (nextFrame || !stepMode) {
  106. curFrame++;
  107. }
  108. if (curFrame >= theMesh.frames) {
  109. // mf: do frame rate calcs here
  110. if( !frameCount ) {
  111. _ftime( &baseTime );
  112. }
  113. else {
  114. if( displayFrameRate ) {
  115. _ftime( &thisTime );
  116. elapsed = thisTime.time + thisTime.millitm/1000.0 -
  117. (baseTime.time + baseTime.millitm/1000.0);
  118. if( elapsed == 0.0 )
  119. printf( "Frame rate = unknown\n" );
  120. else {
  121. frameRate = frameCount / elapsed;
  122. printf( "Frame rate = %5.2f fps\n", frameRate );
  123. }
  124. }
  125. }
  126. frameCount += theMesh.frames;
  127. curFrame = 0;
  128. }
  129. if ((nextFrame || !stepMode) && spinMode) {
  130. glRotatef(5.0, 0.0, 0.0, 1.0);
  131. }
  132. nextFrame = 0;
  133. for (i = 0; i < theMesh.widthX; i++) {
  134. glBegin(GL_QUAD_STRIP);
  135. lastColor = NULL;
  136. for (j = 0; j < theMesh.widthY; j++) {
  137. facet = GETFACET(curFrame, i, j);
  138. if (!smooth && lighting) {
  139. glNormal3fv(facet->normal);
  140. }
  141. if (lighting) {
  142. if (rgb) {
  143. thisColor = facet->color;
  144. glColor3fv(facet->color);
  145. } else {
  146. thisColor = facet->color;
  147. glMaterialfv(GL_FRONT_AND_BACK, GL_COLOR_INDEXES,
  148. facet->color);
  149. }
  150. } else {
  151. if (rgb) {
  152. thisColor = facet->color;
  153. glColor3fv(facet->color);
  154. } else {
  155. thisColor = facet->color;
  156. glIndexf(facet->color[1]);
  157. }
  158. }
  159. if (!lastColor || (thisColor[0] != lastColor[0] && smooth)) {
  160. if (lastColor) {
  161. glEnd();
  162. glBegin(GL_QUAD_STRIP);
  163. }
  164. coord = GETCOORD(curFrame, i, j);
  165. if (smooth && lighting) {
  166. glNormal3fv(coord->normal);
  167. }
  168. glVertex3fv(coord->vertex);
  169. coord = GETCOORD(curFrame, i+1, j);
  170. if (smooth && lighting) {
  171. glNormal3fv(coord->normal);
  172. }
  173. glVertex3fv(coord->vertex);
  174. }
  175. coord = GETCOORD(curFrame, i, j+1);
  176. if (smooth && lighting) {
  177. glNormal3fv(coord->normal);
  178. }
  179. glVertex3fv(coord->vertex);
  180. coord = GETCOORD(curFrame, i+1, j+1);
  181. if (smooth && lighting) {
  182. glNormal3fv(coord->normal);
  183. }
  184. glVertex3fv(coord->vertex);
  185. lastColor = thisColor;
  186. }
  187. glEnd();
  188. }
  189. glFlush();
  190. if (doubleBuffer && !noSwap) {
  191. tkSwapBuffers();
  192. }
  193. }
  194. static void SetColorMap(void)
  195. {
  196. static float green[3] = {0.2, 1.0, 0.2};
  197. static float red[3] = {1.0, 0.2, 0.2};
  198. float *color, percent;
  199. GLint *indexes, entries, i, j;
  200. long buf[4];
  201. entries = tkGetColorMapSize();
  202. colorIndexes1[0] = 1;
  203. colorIndexes1[1] = 1 + (GLint)((entries - 1) * 0.3);
  204. colorIndexes1[2] = (GLint)((entries - 1) * 0.5);
  205. colorIndexes2[0] = 1 + (GLint)((entries - 1) * 0.5);
  206. colorIndexes2[1] = 1 + (GLint)((entries - 1) * 0.8);
  207. colorIndexes2[2] = entries - 1;
  208. for (i = 0; i < 2; i++) {
  209. switch (i) {
  210. case 0:
  211. color = green;
  212. indexes = colorIndexes1;
  213. break;
  214. case 1:
  215. color = red;
  216. indexes = colorIndexes2;
  217. break;
  218. }
  219. for (j = indexes[0]; j < indexes[1]; j++) {
  220. percent = 0.2 + 0.8 * (j - indexes[0]) /
  221. (float)(indexes[1] - indexes[0]);
  222. tkSetOneColor(j, percent*color[0], percent*color[1],
  223. percent*color[2]);
  224. }
  225. for (j=indexes[1]; j<=indexes[2]; j++) {
  226. percent = (j - indexes[1]) / (float)(indexes[2] - indexes[1]);
  227. tkSetOneColor(j, percent*(1-color[0])+color[0],
  228. percent*(1-color[1])+color[1],
  229. percent*(1-color[2])+color[2]);
  230. }
  231. }
  232. }
  233. static void InitMesh(void)
  234. {
  235. struct coord *coord;
  236. struct facet *facet;
  237. float dp1[3], dp2[3];
  238. float *pt1, *pt2, *pt3;
  239. float angle, d, x, y;
  240. GLint numFacets, numCoords, frameNum, i, j;
  241. theMesh.widthX = widthX;
  242. theMesh.widthY = widthY;
  243. theMesh.frames = frames;
  244. numFacets = widthX * widthY;
  245. numCoords = (widthX + 1) * (widthY + 1);
  246. theMesh.numCoords = numCoords;
  247. theMesh.numFacets = numFacets;
  248. theMesh.coords = (struct coord *)malloc(frames*numCoords*
  249. sizeof(struct coord));
  250. theMesh.facets = (struct facet *)malloc(frames*numFacets*
  251. sizeof(struct facet));
  252. if (theMesh.coords == NULL || theMesh.facets == NULL) {
  253. printf("Out of memory.\n");
  254. tkQuit();
  255. }
  256. for (frameNum = 0; frameNum < frames; frameNum++) {
  257. for (i = 0; i <= widthX; i++) {
  258. x = i / (float)widthX;
  259. for (j = 0; j <= widthY; j++) {
  260. y = j / (float)widthY;
  261. d = sqrt(x*x+y*y);
  262. if (d == 0.0) {
  263. d = 0.0001;
  264. }
  265. angle = 2 * PI * d + (2 * PI / frames * frameNum);
  266. coord = GETCOORD(frameNum, i, j);
  267. coord->vertex[0] = x - 0.5;
  268. coord->vertex[1] = y - 0.5;
  269. coord->vertex[2] = (height - height * d) * cos(angle);
  270. coord->normal[0] = -(height / d) * x * ((1 - d) * 2 * PI *
  271. sin(angle) + cos(angle));
  272. coord->normal[1] = -(height / d) * y * ((1 - d) * 2 * PI *
  273. sin(angle) + cos(angle));
  274. coord->normal[2] = -1;
  275. d = 1.0 / sqrt(coord->normal[0]*coord->normal[0]+
  276. coord->normal[1]*coord->normal[1]+1);
  277. coord->normal[0] *= d;
  278. coord->normal[1] *= d;
  279. coord->normal[2] *= d;
  280. }
  281. }
  282. for (i = 0; i < widthX; i++) {
  283. for (j = 0; j < widthY; j++) {
  284. facet = GETFACET(frameNum, i, j);
  285. if (((i/checkerSize)%2)^(j/checkerSize)%2) {
  286. if (rgb) {
  287. facet->color[0] = 1.0;
  288. facet->color[1] = 0.2;
  289. facet->color[2] = 0.2;
  290. } else {
  291. facet->color[0] = colorIndexes1[0];
  292. facet->color[1] = colorIndexes1[1];
  293. facet->color[2] = colorIndexes1[2];
  294. }
  295. } else {
  296. if (rgb) {
  297. facet->color[0] = 0.2;
  298. facet->color[1] = 1.0;
  299. facet->color[2] = 0.2;
  300. } else {
  301. facet->color[0] = colorIndexes2[0];
  302. facet->color[1] = colorIndexes2[1];
  303. facet->color[2] = colorIndexes2[2];
  304. }
  305. }
  306. pt1 = GETCOORD(frameNum, i, j)->vertex;
  307. pt2 = GETCOORD(frameNum, i, j+1)->vertex;
  308. pt3 = GETCOORD(frameNum, i+1, j+1)->vertex;
  309. dp1[0] = pt2[0] - pt1[0];
  310. dp1[1] = pt2[1] - pt1[1];
  311. dp1[2] = pt2[2] - pt1[2];
  312. dp2[0] = pt3[0] - pt2[0];
  313. dp2[1] = pt3[1] - pt2[1];
  314. dp2[2] = pt3[2] - pt2[2];
  315. facet->normal[0] = dp1[1] * dp2[2] - dp1[2] * dp2[1];
  316. facet->normal[1] = dp1[2] * dp2[0] - dp1[0] * dp2[2];
  317. facet->normal[2] = dp1[0] * dp2[1] - dp1[1] * dp2[0];
  318. d = 1.0 / sqrt(facet->normal[0]*facet->normal[0]+
  319. facet->normal[1]*facet->normal[1]+
  320. facet->normal[2]*facet->normal[2]);
  321. facet->normal[0] *= d;
  322. facet->normal[1] *= d;
  323. facet->normal[2] *= d;
  324. }
  325. }
  326. }
  327. }
  328. static void InitMaterials(void)
  329. {
  330. static float ambient[] = {0.1, 0.1, 0.1, 1.0};
  331. static float diffuse[] = {0.5, 1.0, 1.0, 1.0};
  332. static float position[] = {90.0, 90.0, 150.0, 0.0};
  333. static float front_mat_shininess[] = {60.0};
  334. static float front_mat_specular[] = {0.2, 0.2, 0.2, 1.0};
  335. static float front_mat_diffuse[] = {0.5, 0.28, 0.38, 1.0};
  336. static float back_mat_shininess[] = {60.0};
  337. static float back_mat_specular[] = {0.5, 0.5, 0.2, 1.0};
  338. static float back_mat_diffuse[] = {1.0, 1.0, 0.2, 1.0};
  339. static float lmodel_ambient[] = {1.0, 1.0, 1.0, 1.0};
  340. static float lmodel_twoside[] = {GL_TRUE};
  341. glMatrixMode(GL_PROJECTION);
  342. gluPerspective(450, 1.0, 0.5, 10.0);
  343. glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
  344. glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
  345. glLightfv(GL_LIGHT0, GL_POSITION, position);
  346. glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
  347. glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside);
  348. glEnable(GL_LIGHTING);
  349. glEnable(GL_LIGHT0);
  350. glMaterialfv(GL_FRONT, GL_SHININESS, front_mat_shininess);
  351. glMaterialfv(GL_FRONT, GL_SPECULAR, front_mat_specular);
  352. glMaterialfv(GL_FRONT, GL_DIFFUSE, front_mat_diffuse);
  353. glMaterialfv(GL_BACK, GL_SHININESS, back_mat_shininess);
  354. glMaterialfv(GL_BACK, GL_SPECULAR, back_mat_specular);
  355. glMaterialfv(GL_BACK, GL_DIFFUSE, back_mat_diffuse);
  356. if (rgb) {
  357. glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
  358. }
  359. if (rgb) {
  360. glEnable(GL_COLOR_MATERIAL);
  361. } else {
  362. SetColorMap();
  363. }
  364. }
  365. static void InitTexture(void)
  366. {
  367. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  368. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  369. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  370. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  371. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  372. }
  373. static void Init(void)
  374. {
  375. glClearColor(0.0, 0.0, 0.0, 0.0);
  376. if (smooth) {
  377. glShadeModel(GL_SMOOTH);
  378. } else {
  379. glShadeModel(GL_FLAT);
  380. }
  381. glFrontFace(GL_CW);
  382. glDepthFunc(GL_LEQUAL);
  383. glEnable(GL_DEPTH_TEST);
  384. InitMaterials();
  385. InitTexture();
  386. InitMesh();
  387. glMatrixMode(GL_MODELVIEW);
  388. glTranslatef(0.0, 0.4, -1.8);
  389. glScalef(2.0, 2.0, 2.0);
  390. glRotatef(-35.0, 1.0, 0.0, 0.0);
  391. glRotatef(35.0, 0.0, 0.0, 1.0);
  392. }
  393. static void Reshape(int width, int height)
  394. {
  395. glViewport(0, 0, (GLint)width, (GLint)height);
  396. }
  397. static GLenum Key(int key, GLenum mask)
  398. {
  399. switch (key) {
  400. case TK_ESCAPE:
  401. tkQuit();
  402. case TK_c:
  403. contouring++;
  404. if (contouring == 1) {
  405. static GLfloat map[4] = {0, 0, 20, 0};
  406. glTexImage2D(GL_TEXTURE_2D, 0, 3, 4, 4, 0, GL_LUMINANCE,
  407. GL_UNSIGNED_BYTE, (GLvoid *)contourTexture1);
  408. glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
  409. glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
  410. glTexGenfv(GL_S, GL_OBJECT_PLANE, map);
  411. glTexGenfv(GL_T, GL_OBJECT_PLANE, map);
  412. glEnable(GL_TEXTURE_2D);
  413. glEnable(GL_TEXTURE_GEN_S);
  414. glEnable(GL_TEXTURE_GEN_T);
  415. } else if (contouring == 2) {
  416. static GLfloat map[4] = {0, 0, 20, 0};
  417. glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
  418. glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
  419. glPushMatrix();
  420. glMatrixMode(GL_MODELVIEW);
  421. glLoadIdentity();
  422. glTexGenfv(GL_S, GL_EYE_PLANE, map);
  423. glTexGenfv(GL_T, GL_EYE_PLANE, map);
  424. glPopMatrix();
  425. } else {
  426. contouring = 0;
  427. glDisable(GL_TEXTURE_GEN_S);
  428. glDisable(GL_TEXTURE_GEN_T);
  429. glDisable(GL_TEXTURE_2D);
  430. }
  431. break;
  432. case TK_s:
  433. smooth = !smooth;
  434. if (smooth) {
  435. glShadeModel(GL_SMOOTH);
  436. } else {
  437. glShadeModel(GL_FLAT);
  438. }
  439. break;
  440. case TK_l:
  441. lighting = !lighting;
  442. if (lighting) {
  443. glEnable(GL_LIGHTING);
  444. glEnable(GL_LIGHT0);
  445. if (rgb) {
  446. glEnable(GL_COLOR_MATERIAL);
  447. }
  448. } else {
  449. glDisable(GL_LIGHTING);
  450. glDisable(GL_LIGHT0);
  451. if (rgb) {
  452. glDisable(GL_COLOR_MATERIAL);
  453. }
  454. }
  455. break;
  456. case TK_d:
  457. depth = !depth;
  458. if (depth) {
  459. glEnable(GL_DEPTH_TEST);
  460. clearMask |= GL_DEPTH_BUFFER_BIT;
  461. } else {
  462. glDisable(GL_DEPTH_TEST);
  463. clearMask &= ~GL_DEPTH_BUFFER_BIT;
  464. }
  465. break;
  466. case TK_SPACE:
  467. stepMode = !stepMode;
  468. if (stepMode) {
  469. tkIdleFunc(0);
  470. tkDisplayFunc(Animate);
  471. } else {
  472. tkIdleFunc(Animate);
  473. tkDisplayFunc(0);
  474. }
  475. break;
  476. case TK_n:
  477. if (stepMode) {
  478. nextFrame = 1;
  479. }
  480. break;
  481. case TK_f:
  482. displayFrameRate = !displayFrameRate;
  483. frameCount = 0;
  484. break;
  485. case TK_a:
  486. spinMode = !spinMode;
  487. break;
  488. default:
  489. return GL_FALSE;
  490. }
  491. return GL_TRUE;
  492. }
  493. static GLenum Args(int argc, char **argv)
  494. {
  495. GLint i;
  496. rgb = GL_TRUE;
  497. doubleBuffer = GL_TRUE;
  498. directRender = GL_FALSE;
  499. noSwap = GL_FALSE;
  500. noClear = GL_FALSE;
  501. frames = 10;
  502. widthX = 10;
  503. widthY = 10;
  504. checkerSize = 2;
  505. height = 0.2;
  506. for (i = 1; i < argc; i++) {
  507. if (strcmp(argv[i], "-ci") == 0) {
  508. rgb = GL_FALSE;
  509. } else if (strcmp(argv[i], "-rgb") == 0) {
  510. rgb = GL_TRUE;
  511. } else if (strcmp(argv[i], "-sb") == 0) {
  512. doubleBuffer = GL_FALSE;
  513. } else if (strcmp(argv[i], "-db") == 0) {
  514. doubleBuffer = GL_TRUE;
  515. } else if (strcmp(argv[i], "-dr") == 0) {
  516. directRender = GL_TRUE;
  517. } else if (strcmp(argv[i], "-ir") == 0) {
  518. directRender = GL_FALSE;
  519. } else if (strcmp(argv[i], "-noswap") == 0) {
  520. noSwap = GL_TRUE;
  521. } else if (strcmp(argv[i], "-noclear") == 0) {
  522. noClear = GL_TRUE;
  523. } else if (strcmp(argv[i], "-grid") == 0) {
  524. if (i+2 >= argc || argv[i+1][0] == '-' || argv[i+2][0] == '-') {
  525. printf("-grid (No numbers).\n");
  526. return GL_FALSE;
  527. } else {
  528. widthX = atoi(argv[++i]);
  529. widthY = atoi(argv[++i]);
  530. }
  531. } else if (strcmp(argv[i], "-size") == 0) {
  532. if (i+1 >= argc || argv[i+1][0] == '-') {
  533. printf("-checker (No number).\n");
  534. return GL_FALSE;
  535. } else {
  536. checkerSize = atoi(argv[++i]);
  537. }
  538. } else if (strcmp(argv[i], "-wave") == 0) {
  539. if (i+1 >= argc || argv[i+1][0] == '-') {
  540. printf("-wave (No number).\n");
  541. return GL_FALSE;
  542. } else {
  543. height = atof(argv[++i]);
  544. }
  545. } else if (strcmp(argv[i], "-frames") == 0) {
  546. if (i+1 >= argc || argv[i+1][0] == '-') {
  547. printf("-frames (No number).\n");
  548. return GL_FALSE;
  549. } else {
  550. frames = atoi(argv[++i]);
  551. }
  552. } else {
  553. printf("%s (Bad option).\n", argv[i]);
  554. return GL_FALSE;
  555. }
  556. }
  557. return GL_TRUE;
  558. }
  559. void main(int argc, char **argv)
  560. {
  561. GLenum type;
  562. if (Args(argc, argv) == GL_FALSE) {
  563. tkQuit();
  564. }
  565. tkInitPosition(10, 30, 300, 300);
  566. type = TK_DEPTH16;
  567. type |= (rgb) ? TK_RGB : TK_INDEX;
  568. type |= (doubleBuffer) ? TK_DOUBLE : TK_SINGLE;
  569. type |= (directRender) ? TK_DIRECT : TK_INDIRECT;
  570. tkInitDisplayMode(type);
  571. if (tkInitWindow("Wave Demo") == GL_FALSE) {
  572. tkQuit();
  573. }
  574. Init();
  575. tkExposeFunc(Reshape);
  576. tkReshapeFunc(Reshape);
  577. tkKeyDownFunc(Key);
  578. tkIdleFunc(Animate);
  579. tkExec();
  580. }