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.

746 lines
18 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 <glwin.h>
  45. #include <gl/glu.h>
  46. #pragma warning(disable:4244)
  47. #define PI 3.14159265358979323846
  48. #define GETCOORD(frame, x, y) (&(theMesh.coords[frame*theMesh.numCoords+(x)+(y)*(theMesh.widthX+1)]))
  49. #define GETFACET(frame, x, y) (&(theMesh.facets[frame*theMesh.numFacets+(x)+(y)*theMesh.widthX]))
  50. GLenum rgb, doubleBuffer, directRender;
  51. GLenum noSwap, noClear, useMcd;
  52. GLint colorIndexes1[3];
  53. GLint colorIndexes2[3];
  54. GLenum clearMask = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT;
  55. GLenum smooth = GL_TRUE;
  56. GLenum lighting = GL_TRUE;
  57. GLenum depth = GL_TRUE;
  58. GLenum stepMode = GL_FALSE;
  59. GLenum spinMode = GL_FALSE;
  60. GLint contouring = 0;
  61. GLint widthX, widthY;
  62. GLint checkerSize;
  63. float height;
  64. GLint frames, curFrame = 0, nextFrame = 0;
  65. GLboolean displayFrameRate = GL_FALSE;
  66. static GLint frameCount = 0;
  67. struct facet {
  68. float color[3];
  69. float normal[3];
  70. };
  71. struct coord {
  72. float vertex[3];
  73. float normal[3];
  74. };
  75. struct mesh {
  76. GLint widthX, widthY;
  77. GLint numFacets;
  78. GLint numCoords;
  79. GLint frames;
  80. struct coord *coords;
  81. struct facet *facets;
  82. } theMesh;
  83. GLubyte contourTexture1[] = {
  84. 255, 255, 255, 255,
  85. 255, 255, 255, 255,
  86. 255, 255, 255, 255,
  87. 127, 127, 127, 127,
  88. };
  89. GLubyte contourTexture2[] = {
  90. 255, 255, 255, 255,
  91. 255, 127, 127, 127,
  92. 255, 127, 127, 127,
  93. 255, 127, 127, 127,
  94. };
  95. #define ANIMATE_ALL
  96. #define STAGGER_WINDOWS
  97. #define SWAP_MULTIPLE
  98. // #define HIDE_UNDER
  99. #define NWIN 4
  100. int nWin;
  101. GLWINDOW gwWin[NWIN];
  102. int iFront;
  103. WGLSWAP wswaps[NWIN];
  104. DWORD adwFlags[NWIN] =
  105. {
  106. GLWIN_Z_BUFFER_16,
  107. GLWIN_Z_BUFFER_16 | GLWIN_BACK_BUFFER,
  108. #if NWIN > 2
  109. GLWIN_Z_BUFFER_32,
  110. #endif
  111. #if NWIN > 3
  112. GLWIN_Z_BUFFER_32 | GLWIN_BACK_BUFFER
  113. #endif
  114. };
  115. void Quit(void)
  116. {
  117. int i;
  118. for (i = 0; i < nWin; i++)
  119. {
  120. if (gwWin[i] != NULL)
  121. {
  122. glwinDestroyWindow(gwWin[i]);
  123. }
  124. }
  125. exit(1);
  126. }
  127. static void Animate(GLWINDOW gw)
  128. {
  129. struct coord *coord;
  130. struct facet *facet;
  131. float *lastColor;
  132. float *thisColor;
  133. GLint i, j;
  134. static struct _timeb thisTime, baseTime;
  135. double elapsed, frameRate, deltat;
  136. if (stepMode)
  137. {
  138. return;
  139. }
  140. glwinMakeCurrent(gw);
  141. if (!noClear)
  142. {
  143. glClear(clearMask);
  144. }
  145. if (nextFrame || !stepMode) {
  146. curFrame++;
  147. }
  148. if (curFrame >= theMesh.frames) {
  149. // mf: do frame rate calcs here
  150. if( !frameCount ) {
  151. _ftime( &baseTime );
  152. }
  153. else {
  154. if( displayFrameRate ) {
  155. _ftime( &thisTime );
  156. elapsed = thisTime.time + thisTime.millitm/1000.0 -
  157. (baseTime.time + baseTime.millitm/1000.0);
  158. if( elapsed == 0.0 )
  159. printf( "Frame rate = unknown\n" );
  160. else {
  161. frameRate = frameCount / elapsed;
  162. printf( "Frame rate = %5.2f fps\n", frameRate );
  163. }
  164. }
  165. }
  166. frameCount += theMesh.frames;
  167. curFrame = 0;
  168. }
  169. if ((nextFrame || !stepMode) && spinMode) {
  170. glRotatef(5.0, 0.0, 0.0, 1.0);
  171. }
  172. nextFrame = 0;
  173. for (i = 0; i < theMesh.widthX; i++) {
  174. glBegin(GL_QUAD_STRIP);
  175. lastColor = NULL;
  176. for (j = 0; j < theMesh.widthY; j++) {
  177. facet = GETFACET(curFrame, i, j);
  178. if (!smooth && lighting) {
  179. glNormal3fv(facet->normal);
  180. }
  181. if (lighting) {
  182. if (rgb) {
  183. thisColor = facet->color;
  184. glColor3fv(facet->color);
  185. } else {
  186. thisColor = facet->color;
  187. glMaterialfv(GL_FRONT_AND_BACK, GL_COLOR_INDEXES,
  188. facet->color);
  189. }
  190. } else {
  191. if (rgb) {
  192. thisColor = facet->color;
  193. glColor3fv(facet->color);
  194. } else {
  195. thisColor = facet->color;
  196. glIndexf(facet->color[1]);
  197. }
  198. }
  199. if (!lastColor || (thisColor[0] != lastColor[0] && smooth)) {
  200. if (lastColor) {
  201. glEnd();
  202. glBegin(GL_QUAD_STRIP);
  203. }
  204. coord = GETCOORD(curFrame, i, j);
  205. if (smooth && lighting) {
  206. glNormal3fv(coord->normal);
  207. }
  208. glVertex3fv(coord->vertex);
  209. coord = GETCOORD(curFrame, i+1, j);
  210. if (smooth && lighting) {
  211. glNormal3fv(coord->normal);
  212. }
  213. glVertex3fv(coord->vertex);
  214. }
  215. coord = GETCOORD(curFrame, i, j+1);
  216. if (smooth && lighting) {
  217. glNormal3fv(coord->normal);
  218. }
  219. glVertex3fv(coord->vertex);
  220. coord = GETCOORD(curFrame, i+1, j+1);
  221. if (smooth && lighting) {
  222. glNormal3fv(coord->normal);
  223. }
  224. glVertex3fv(coord->vertex);
  225. lastColor = thisColor;
  226. }
  227. glEnd();
  228. }
  229. glFlush();
  230. #ifndef SWAP_MULTIPLE
  231. if ((glwinGetFlags(gw) & GLWIN_BACK_BUFFER) && !noSwap) {
  232. glwinSwapBuffers(gw);
  233. }
  234. #endif
  235. }
  236. void AnimateN(GLWINDOW gw)
  237. {
  238. #ifdef ANIMATE_ALL
  239. int i;
  240. for (i = 0; i < nWin; i++)
  241. {
  242. Animate(gwWin[i]);
  243. }
  244. #ifdef SWAP_MULTIPLE
  245. wglSwapMultipleBuffers(nWin, wswaps);
  246. #endif
  247. #else
  248. Animate(gwWin[iFront]);
  249. #ifdef SWAP_MULTIPLE
  250. wglSwapMultipleBuffers(1, &wswaps[iFront]);
  251. #endif
  252. #endif
  253. }
  254. static void InitMesh(void)
  255. {
  256. struct coord *coord;
  257. struct facet *facet;
  258. float dp1[3], dp2[3];
  259. float *pt1, *pt2, *pt3;
  260. float angle, d, x, y;
  261. GLint numFacets, numCoords, frameNum, i, j;
  262. theMesh.widthX = widthX;
  263. theMesh.widthY = widthY;
  264. theMesh.frames = frames;
  265. numFacets = widthX * widthY;
  266. numCoords = (widthX + 1) * (widthY + 1);
  267. theMesh.numCoords = numCoords;
  268. theMesh.numFacets = numFacets;
  269. theMesh.coords = (struct coord *)malloc(frames*numCoords*
  270. sizeof(struct coord));
  271. theMesh.facets = (struct facet *)malloc(frames*numFacets*
  272. sizeof(struct facet));
  273. if (theMesh.coords == NULL || theMesh.facets == NULL) {
  274. printf("Out of memory.\n");
  275. exit(1);
  276. }
  277. for (frameNum = 0; frameNum < frames; frameNum++) {
  278. for (i = 0; i <= widthX; i++) {
  279. x = i / (float)widthX;
  280. for (j = 0; j <= widthY; j++) {
  281. y = j / (float)widthY;
  282. d = sqrt(x*x+y*y);
  283. if (d == 0.0) {
  284. d = 0.0001;
  285. }
  286. angle = 2 * PI * d + (2 * PI / frames * frameNum);
  287. coord = GETCOORD(frameNum, i, j);
  288. coord->vertex[0] = x - 0.5;
  289. coord->vertex[1] = y - 0.5;
  290. coord->vertex[2] = (height - height * d) * cos(angle);
  291. coord->normal[0] = -(height / d) * x * ((1 - d) * 2 * PI *
  292. sin(angle) + cos(angle));
  293. coord->normal[1] = -(height / d) * y * ((1 - d) * 2 * PI *
  294. sin(angle) + cos(angle));
  295. coord->normal[2] = -1;
  296. d = 1.0 / sqrt(coord->normal[0]*coord->normal[0]+
  297. coord->normal[1]*coord->normal[1]+1);
  298. coord->normal[0] *= d;
  299. coord->normal[1] *= d;
  300. coord->normal[2] *= d;
  301. }
  302. }
  303. for (i = 0; i < widthX; i++) {
  304. for (j = 0; j < widthY; j++) {
  305. facet = GETFACET(frameNum, i, j);
  306. if (((i/checkerSize)%2)^(j/checkerSize)%2) {
  307. if (rgb) {
  308. facet->color[0] = 1.0;
  309. facet->color[1] = 0.2;
  310. facet->color[2] = 0.2;
  311. } else {
  312. facet->color[0] = colorIndexes1[0];
  313. facet->color[1] = colorIndexes1[1];
  314. facet->color[2] = colorIndexes1[2];
  315. }
  316. } else {
  317. if (rgb) {
  318. facet->color[0] = 0.2;
  319. facet->color[1] = 1.0;
  320. facet->color[2] = 0.2;
  321. } else {
  322. facet->color[0] = colorIndexes2[0];
  323. facet->color[1] = colorIndexes2[1];
  324. facet->color[2] = colorIndexes2[2];
  325. }
  326. }
  327. pt1 = GETCOORD(frameNum, i, j)->vertex;
  328. pt2 = GETCOORD(frameNum, i, j+1)->vertex;
  329. pt3 = GETCOORD(frameNum, i+1, j+1)->vertex;
  330. dp1[0] = pt2[0] - pt1[0];
  331. dp1[1] = pt2[1] - pt1[1];
  332. dp1[2] = pt2[2] - pt1[2];
  333. dp2[0] = pt3[0] - pt2[0];
  334. dp2[1] = pt3[1] - pt2[1];
  335. dp2[2] = pt3[2] - pt2[2];
  336. facet->normal[0] = dp1[1] * dp2[2] - dp1[2] * dp2[1];
  337. facet->normal[1] = dp1[2] * dp2[0] - dp1[0] * dp2[2];
  338. facet->normal[2] = dp1[0] * dp2[1] - dp1[1] * dp2[0];
  339. d = 1.0 / sqrt(facet->normal[0]*facet->normal[0]+
  340. facet->normal[1]*facet->normal[1]+
  341. facet->normal[2]*facet->normal[2]);
  342. facet->normal[0] *= d;
  343. facet->normal[1] *= d;
  344. facet->normal[2] *= d;
  345. }
  346. }
  347. }
  348. }
  349. static void InitMaterials(void)
  350. {
  351. static float ambient[] = {0.1, 0.1, 0.1, 1.0};
  352. static float diffuse[] = {0.5, 1.0, 1.0, 1.0};
  353. static float position[] = {90.0, 90.0, 150.0, 0.0};
  354. static float front_mat_shininess[] = {60.0};
  355. static float front_mat_specular[] = {0.2, 0.2, 0.2, 1.0};
  356. static float front_mat_diffuse[] = {0.5, 0.28, 0.38, 1.0};
  357. static float back_mat_shininess[] = {60.0};
  358. static float back_mat_specular[] = {0.5, 0.5, 0.2, 1.0};
  359. static float back_mat_diffuse[] = {1.0, 1.0, 0.2, 1.0};
  360. static float lmodel_ambient[] = {1.0, 1.0, 1.0, 1.0};
  361. static float lmodel_twoside[] = {GL_TRUE};
  362. glMatrixMode(GL_PROJECTION);
  363. gluPerspective(450, 1.0, 0.5, 10.0);
  364. glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
  365. glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
  366. glLightfv(GL_LIGHT0, GL_POSITION, position);
  367. glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
  368. glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside);
  369. glEnable(GL_LIGHTING);
  370. glEnable(GL_LIGHT0);
  371. glMaterialfv(GL_FRONT, GL_SHININESS, front_mat_shininess);
  372. glMaterialfv(GL_FRONT, GL_SPECULAR, front_mat_specular);
  373. glMaterialfv(GL_FRONT, GL_DIFFUSE, front_mat_diffuse);
  374. glMaterialfv(GL_BACK, GL_SHININESS, back_mat_shininess);
  375. glMaterialfv(GL_BACK, GL_SPECULAR, back_mat_specular);
  376. glMaterialfv(GL_BACK, GL_DIFFUSE, back_mat_diffuse);
  377. if (rgb) {
  378. glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
  379. }
  380. if (rgb) {
  381. glEnable(GL_COLOR_MATERIAL);
  382. } else {
  383. Quit();
  384. }
  385. }
  386. static void InitTexture(void)
  387. {
  388. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  389. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  390. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  391. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  392. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  393. }
  394. static void Init(void)
  395. {
  396. glClearColor(0.0, 0.0, 0.0, 0.0);
  397. if (smooth) {
  398. glShadeModel(GL_SMOOTH);
  399. } else {
  400. glShadeModel(GL_FLAT);
  401. }
  402. glFrontFace(GL_CW);
  403. glDepthFunc(GL_LEQUAL);
  404. glEnable(GL_DEPTH_TEST);
  405. InitMaterials();
  406. InitTexture();
  407. glMatrixMode(GL_MODELVIEW);
  408. glTranslatef(0.0, 0.4, -1.8);
  409. glScalef(2.0, 2.0, 2.0);
  410. glRotatef(-35.0, 1.0, 0.0, 0.0);
  411. glRotatef(35.0, 0.0, 0.0, 1.0);
  412. }
  413. static GLenum Key(UINT key)
  414. {
  415. #ifdef HIDE_UNDER
  416. int iOldFront;
  417. #endif
  418. switch (key) {
  419. case VK_ESCAPE:
  420. Quit();
  421. case 'C':
  422. contouring++;
  423. if (contouring == 1) {
  424. static GLfloat map[4] = {0, 0, 20, 0};
  425. glTexImage2D(GL_TEXTURE_2D, 0, 3, 4, 4, 0, GL_LUMINANCE,
  426. GL_UNSIGNED_BYTE, (GLvoid *)contourTexture1);
  427. glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
  428. glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
  429. glTexGenfv(GL_S, GL_OBJECT_PLANE, map);
  430. glTexGenfv(GL_T, GL_OBJECT_PLANE, map);
  431. glEnable(GL_TEXTURE_2D);
  432. glEnable(GL_TEXTURE_GEN_S);
  433. glEnable(GL_TEXTURE_GEN_T);
  434. } else if (contouring == 2) {
  435. static GLfloat map[4] = {0, 0, 20, 0};
  436. glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
  437. glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
  438. glPushMatrix();
  439. glMatrixMode(GL_MODELVIEW);
  440. glLoadIdentity();
  441. glTexGenfv(GL_S, GL_EYE_PLANE, map);
  442. glTexGenfv(GL_T, GL_EYE_PLANE, map);
  443. glPopMatrix();
  444. } else {
  445. contouring = 0;
  446. glDisable(GL_TEXTURE_GEN_S);
  447. glDisable(GL_TEXTURE_GEN_T);
  448. glDisable(GL_TEXTURE_2D);
  449. }
  450. break;
  451. case 'S':
  452. smooth = !smooth;
  453. if (smooth) {
  454. glShadeModel(GL_SMOOTH);
  455. } else {
  456. glShadeModel(GL_FLAT);
  457. }
  458. break;
  459. case 'L':
  460. lighting = !lighting;
  461. if (lighting) {
  462. glEnable(GL_LIGHTING);
  463. glEnable(GL_LIGHT0);
  464. if (rgb) {
  465. glEnable(GL_COLOR_MATERIAL);
  466. }
  467. } else {
  468. glDisable(GL_LIGHTING);
  469. glDisable(GL_LIGHT0);
  470. if (rgb) {
  471. glDisable(GL_COLOR_MATERIAL);
  472. }
  473. }
  474. break;
  475. case 'D':
  476. depth = !depth;
  477. if (depth) {
  478. glEnable(GL_DEPTH_TEST);
  479. clearMask |= GL_DEPTH_BUFFER_BIT;
  480. } else {
  481. glDisable(GL_DEPTH_TEST);
  482. clearMask &= ~GL_DEPTH_BUFFER_BIT;
  483. }
  484. break;
  485. case VK_SPACE:
  486. stepMode = !stepMode;
  487. break;
  488. case 'N':
  489. if (stepMode) {
  490. nextFrame = 1;
  491. }
  492. break;
  493. case 'F':
  494. displayFrameRate = !displayFrameRate;
  495. frameCount = 0;
  496. break;
  497. case 'A':
  498. spinMode = !spinMode;
  499. break;
  500. case 'Z':
  501. #ifdef HIDE_UNDER
  502. iOldFront = iFront;
  503. #endif
  504. iFront = (iFront+1) % nWin;
  505. #ifdef HIDE_UNDER
  506. ShowWindow(glwinGetHwnd(gwWin[iFront]), SW_SHOW);
  507. ShowWindow(glwinGetHwnd(gwWin[iOldFront]), SW_HIDE);
  508. #else
  509. SetWindowPos(glwinGetHwnd(gwWin[iFront]), HWND_TOP, 0, 0, 0, 0,
  510. SWP_NOMOVE | SWP_NOSIZE);
  511. #endif
  512. break;
  513. default:
  514. return GL_FALSE;
  515. }
  516. return GL_TRUE;
  517. }
  518. BOOL Message(GLWINDOW gw, HWND hwnd, UINT uiMsg, WPARAM wpm, LPARAM lpm,
  519. LRESULT *plr)
  520. {
  521. switch(uiMsg)
  522. {
  523. case WM_KEYDOWN:
  524. Key((UINT)wpm);
  525. break;
  526. default:
  527. return FALSE;
  528. }
  529. *plr = 0;
  530. return TRUE;
  531. }
  532. static GLenum Args(int argc, char **argv)
  533. {
  534. GLint i;
  535. rgb = GL_TRUE;
  536. doubleBuffer = GL_TRUE;
  537. directRender = GL_FALSE;
  538. noSwap = GL_FALSE;
  539. noClear = GL_FALSE;
  540. useMcd = GL_FALSE;
  541. nWin = NWIN;
  542. frames = 10;
  543. widthX = 10;
  544. widthY = 10;
  545. checkerSize = 2;
  546. height = 0.2;
  547. for (i = 1; i < argc; i++) {
  548. if (strcmp(argv[i], "-ci") == 0) {
  549. rgb = GL_FALSE;
  550. } else if (strcmp(argv[i], "-rgb") == 0) {
  551. rgb = GL_TRUE;
  552. } else if (strcmp(argv[i], "-sb") == 0) {
  553. doubleBuffer = GL_FALSE;
  554. } else if (strcmp(argv[i], "-db") == 0) {
  555. doubleBuffer = GL_TRUE;
  556. } else if (strcmp(argv[i], "-dr") == 0) {
  557. directRender = GL_TRUE;
  558. } else if (strcmp(argv[i], "-ir") == 0) {
  559. directRender = GL_FALSE;
  560. } else if (strcmp(argv[i], "-noswap") == 0) {
  561. noSwap = GL_TRUE;
  562. } else if (strcmp(argv[i], "-noclear") == 0) {
  563. noClear = GL_TRUE;
  564. } else if (strcmp(argv[i], "-mcd") == 0) {
  565. useMcd = GL_TRUE;
  566. } else if (strcmp(argv[i], "-nwin") == 0) {
  567. if (i+1 >= argc || argv[i+1][0] == '-') {
  568. printf("-nwin (No numbers).\n");
  569. return GL_FALSE;
  570. } else {
  571. nWin = atoi(argv[++i]);
  572. }
  573. } else if (strcmp(argv[i], "-grid") == 0) {
  574. if (i+2 >= argc || argv[i+1][0] == '-' || argv[i+2][0] == '-') {
  575. printf("-grid (No numbers).\n");
  576. return GL_FALSE;
  577. } else {
  578. widthX = atoi(argv[++i]);
  579. widthY = atoi(argv[++i]);
  580. }
  581. } else if (strcmp(argv[i], "-size") == 0) {
  582. if (i+1 >= argc || argv[i+1][0] == '-') {
  583. printf("-checker (No number).\n");
  584. return GL_FALSE;
  585. } else {
  586. checkerSize = atoi(argv[++i]);
  587. }
  588. } else if (strcmp(argv[i], "-wave") == 0) {
  589. if (i+1 >= argc || argv[i+1][0] == '-') {
  590. printf("-wave (No number).\n");
  591. return GL_FALSE;
  592. } else {
  593. height = atof(argv[++i]);
  594. }
  595. } else if (strcmp(argv[i], "-frames") == 0) {
  596. if (i+1 >= argc || argv[i+1][0] == '-') {
  597. printf("-frames (No number).\n");
  598. return GL_FALSE;
  599. } else {
  600. frames = atoi(argv[++i]);
  601. }
  602. } else {
  603. printf("%s (Bad option).\n", argv[i]);
  604. return GL_FALSE;
  605. }
  606. }
  607. return GL_TRUE;
  608. }
  609. void __cdecl main(int argc, char **argv)
  610. {
  611. DWORD dwBaseFlags;
  612. DWORD dwFlags;
  613. GLWINDOW gw;
  614. int iWidth, iHeight;
  615. int x, y;
  616. int i;
  617. char achName[80];
  618. if (Args(argc, argv) == GL_FALSE) {
  619. exit(1);
  620. }
  621. InitMesh();
  622. dwBaseFlags = useMcd ? GLWIN_GENERIC_ACCELERATED : 0;
  623. x = 10;
  624. y = 30;
  625. iWidth = 320;
  626. iHeight = 320;
  627. for (i = 0; i < nWin; i++)
  628. {
  629. dwFlags = (adwFlags[i] | dwBaseFlags) ^
  630. (doubleBuffer ? GLWIN_BACK_BUFFER : 0);
  631. sprintf(achName, "Wave Demo Window %d Flags 0x%lX", i, dwFlags);
  632. gw = glwinCreateWindow(NULL, achName, x, y, iWidth, iHeight, dwFlags);
  633. if (gw == NULL)
  634. {
  635. printf("glwinCreateWindow failed with 0x%08lX\n",
  636. glwinGetLastError());
  637. Quit();
  638. }
  639. gwWin[i] = gw;
  640. wswaps[i].hdc = glwinGetHdc(gw);
  641. wswaps[i].uiFlags = WGL_SWAP_MAIN_PLANE;
  642. glwinMakeCurrent(gw);
  643. Init();
  644. glwinMessageCallback(gw, Message);
  645. #ifdef HIDE_UNDER
  646. if (i < nWin-1)
  647. {
  648. ShowWindow(glwinGetHwnd(gw), SW_HIDE);
  649. }
  650. #endif
  651. #ifdef STAGGER_WINDOWS
  652. x += iWidth/3;
  653. y += iHeight/3;
  654. #endif
  655. }
  656. iFront = i-1;
  657. glwinRun(AnimateN);
  658. Quit();
  659. }