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.

827 lines
21 KiB

  1. #include "pch.c"
  2. #pragma hdrstop
  3. #include <time.h>
  4. #include "mazedlg.h"
  5. #include <assert.h>
  6. MazeView vw;
  7. MazeSolution sol;
  8. MazeOptions maze_options =
  9. {
  10. FALSE, // depth_test
  11. RENDER_FLAT, // render mode (WALLS)
  12. RENDER_FLAT, // render mode (FLOOR)
  13. RENDER_FLAT, // render mode (CEILING)
  14. FALSE, // frame_count
  15. FALSE, // top_view
  16. TRUE, // eye_view
  17. FALSE, // single_step
  18. FALSE, // all_alpha
  19. FALSE, // bDither
  20. 1 // nrats
  21. };
  22. float gfAspect = 1.0f; // aspect ratio
  23. #define SST_NEW_MAZE 0
  24. #define SST_MAZE_GROW 1
  25. #define SST_SOLVING 2
  26. #define SST_MAZE_SHRINK 3
  27. #define SST_ROTATE 4
  28. int solve_state = SST_NEW_MAZE;
  29. // Table of textures used. The first entries contain 1 texture for each main
  30. // surface, followed by textures used for various objects
  31. TEXTURE all_textures[NUM_TEXTURES];
  32. // Environment associated with the texture (repetition, palette rotation,..)
  33. // For now, have one for each of the textures in all_textures. But, this
  34. // could be a per-object thing.
  35. TEX_ENV gTexEnv[NUM_TEXTURES];
  36. // texture environment mode
  37. int gTexEnvMode;
  38. // Texture resources for the main surfaces
  39. TEX_RES gTexResSurf[NUM_DEF_SURFACE_TEXTURES] = {
  40. {TEX_BMP, IDB_BRICK}, // default textures
  41. {TEX_BMP, IDB_WOOD},
  42. {TEX_BMP, IDB_CASTLE},
  43. {TEX_A8, IDB_CURL4}, // mandelbrot textures
  44. {TEX_A8, IDB_BHOLE4},
  45. {TEX_A8, IDB_SNOWFLAK},
  46. {TEX_A8, IDB_SWIRLX4}
  47. };
  48. // Texture resources for objects
  49. TEX_RES gTexResObject[NUM_OBJECT_TEXTURES] = {
  50. {TEX_A8, IDB_START},
  51. {TEX_A8, IDB_END},
  52. {TEX_A8, IDB_RAT},
  53. {TEX_A8, IDB_AD},
  54. {TEX_BMP, IDB_COVER}
  55. };
  56. SSContext gssc;
  57. void maze_Init( void *data );
  58. void RotateTexturePalettes( TEX_ENV *pTexEnv, int count, int iRot );
  59. enum {
  60. TIMER_START = 0,
  61. TIMER_STOP
  62. };
  63. void Draw(void)
  64. {
  65. GLbitfield mask;
  66. mask = 0;
  67. if (maze_options.depth_test)
  68. {
  69. mask |= GL_DEPTH_BUFFER_BIT;
  70. }
  71. if (maze_options.render[FLOOR] == RENDER_NONE ||
  72. maze_options.render[CEILING] == RENDER_NONE ||
  73. maze_options.render[WALLS] == RENDER_NONE ||
  74. maze_height < 1.0f)
  75. {
  76. mask |= GL_COLOR_BUFFER_BIT;
  77. }
  78. if (mask != 0)
  79. {
  80. glClear(mask);
  81. }
  82. // Rotate the palettes of any paletted texures by 1
  83. RotateTexturePalettes( gTexEnv, NUM_TEXTURES, 1 );
  84. if (maze_options.eye_view)
  85. {
  86. DrawMaze(&vw);
  87. }
  88. if (maze_options.top_view)
  89. {
  90. DrawTopView(&vw);
  91. }
  92. glFlush();
  93. }
  94. MazeGoal maze_goals[MAX_GOALS];
  95. int ngoals;
  96. Object special_obj[MAX_SPECIALS];
  97. #define MAX_LETTERS 3
  98. Object letters_obj[MAX_LETTERS];
  99. typedef struct _Rat
  100. {
  101. Object obj;
  102. MazeView vw;
  103. MazeSolution sol;
  104. } Rat;
  105. Rat rats[MAX_RATS];
  106. void NewMazeList(void)
  107. {
  108. glNewList(maze_walls_list, GL_COMPILE);
  109. DrawMazeWalls();
  110. glEndList();
  111. }
  112. void UpdateRatPosition(Rat *rat)
  113. {
  114. MoveObject(&rat->obj, rat->vw.pos.x, rat->vw.pos.y);
  115. // Invert the angle because view angles move opposite to
  116. // object angles
  117. rat->obj.ang = FaAdd(0, -rat->vw.ang);
  118. }
  119. // Simple routines to pick cells at random while guaranteeing
  120. // that those cells are unoccupied
  121. static int rnd_cells[MAZE_CELLS];
  122. static int nrnd_cells;
  123. void InitRandomCells(void)
  124. {
  125. int i;
  126. nrnd_cells = MAZE_CELLS;
  127. for (i = 0; i < nrnd_cells; i++)
  128. {
  129. rnd_cells[i] = i;
  130. }
  131. }
  132. void PickRandomCell(IntPt2 *pos)
  133. {
  134. int idx, t;
  135. #if DBG
  136. if (nrnd_cells == 0)
  137. {
  138. MessageBox(GetDesktopWindow(), TEXT("Out of random cells"),
  139. NULL, MB_OK);
  140. pos->x = 0;
  141. pos->y = 0;
  142. return;
  143. }
  144. #endif
  145. idx = rand() % nrnd_cells;
  146. nrnd_cells--;
  147. t = rnd_cells[idx];
  148. rnd_cells[idx] = rnd_cells[nrnd_cells];
  149. pos->x = t % MAZE_GRID;
  150. pos->y = t / MAZE_GRID;
  151. }
  152. void RemoveRandomCell(IntPt2 *pos)
  153. {
  154. int i, idx;
  155. for (i = 0; i < nrnd_cells; i++)
  156. {
  157. idx = rnd_cells[i];
  158. if ((idx % MAZE_GRID) == pos->x &&
  159. (idx / MAZE_GRID) == pos->y)
  160. {
  161. nrnd_cells--;
  162. rnd_cells[i] = rnd_cells[nrnd_cells];
  163. return;
  164. }
  165. }
  166. }
  167. void NewMaze(void)
  168. {
  169. IntPt2 cell, start_cell;
  170. int i, nspecials, nads;
  171. static BOOL firstMaze = TRUE;
  172. // If not in full screen mode, move the maze window around after it's solved
  173. if( !gbTurboMode && !firstMaze )
  174. ss_RandomWindowPos();
  175. InitRandomCells();
  176. if (!InitMaze(&start_cell, maze_goals, &ngoals))
  177. {
  178. printf("InitMaze failed\n");
  179. exit(1);
  180. }
  181. RemoveRandomCell(&start_cell);
  182. cell.x = maze_goals[GOAL_END].clx;
  183. cell.y = maze_goals[GOAL_END].cly;
  184. RemoveRandomCell(&cell);
  185. nspecials = rand() % MAX_SPECIALS;
  186. for (i = 0; i < nspecials; i++)
  187. {
  188. PickRandomCell(&cell);
  189. maze_goals[ngoals].clx = cell.x;
  190. maze_goals[ngoals].cly = cell.y;
  191. maze_goals[ngoals].user = &special_obj[i];
  192. special_obj[i].w = FMAZE_CELL_SIZE/4;
  193. special_obj[i].h = FxFltVal(.25);
  194. special_obj[i].z = special_obj[i].h;
  195. special_obj[i].col = 15;
  196. special_obj[i].draw_style = DRAW_SPECIAL;
  197. special_obj[i].draw_arg = rand() % SPECIAL_ARG_COUNT;
  198. special_obj[i].ang = FaDeg(0);
  199. special_obj[i].user1 = (rand() % 6)+2;
  200. special_obj[i].user2 = rand() % 5;
  201. special_obj[i].user3 = 0;
  202. PlaceObject(&special_obj[i],
  203. CellToMfx(maze_goals[ngoals].clx)+FMAZE_CELL_SIZE/2,
  204. CellToMfx(maze_goals[ngoals].cly)+FMAZE_CELL_SIZE/2);
  205. ngoals++;
  206. }
  207. while (i < MAX_SPECIALS)
  208. {
  209. special_obj[i].cell = NULL;
  210. i++;
  211. }
  212. nads = (rand() % (MAX_LETTERS*2))-MAX_LETTERS+1;
  213. for (i = 0; i < nads; i++)
  214. {
  215. PickRandomCell(&cell);
  216. letters_obj[i].w = FMAZE_CELL_SIZE/3;
  217. letters_obj[i].h = FxFltVal(.33);
  218. letters_obj[i].z = FxFltVal(.5);
  219. letters_obj[i].col = 15;
  220. letters_obj[i].draw_style = DRAW_POLYGON;
  221. letters_obj[i].pTexEnv = &gTexEnv[ TEX_AD ];
  222. letters_obj[i].ang = FaDeg(0);
  223. PlaceObject(&letters_obj[i],
  224. CellToMfx(cell.x)+FMAZE_CELL_SIZE/2,
  225. CellToMfx(cell.y)+FMAZE_CELL_SIZE/2);
  226. }
  227. while (i < MAX_LETTERS)
  228. {
  229. letters_obj[i].cell = NULL;
  230. i++;
  231. }
  232. for (i = 0; i < maze_options.nrats; i++)
  233. {
  234. PickRandomCell(&cell);
  235. rats[i].obj.w = FMAZE_CELL_SIZE/4;
  236. rats[i].obj.h = FxFltVal(.125);
  237. rats[i].obj.z = rats[i].obj.h;
  238. rats[i].obj.col = 16;
  239. rats[i].obj.draw_style = DRAW_POLYGON;
  240. rats[i].obj.pTexEnv = &gTexEnv[ TEX_RAT ];
  241. SolveMazeStart(&rats[i].vw, &maze_cells[0][0], MAZE_GRID, MAZE_GRID,
  242. &cell, SOL_DIR_LEFT,
  243. NULL, 0,
  244. (rand() % 1000) > 500 ? SOL_TURN_LEFT : SOL_TURN_RIGHT,
  245. &rats[i].sol);
  246. // Need to force this to NULL when a new maze is generated so
  247. // that moving doesn't try to use old maze data
  248. rats[i].obj.cell = NULL;
  249. UpdateRatPosition(&rats[i]);
  250. }
  251. NewMazeList();
  252. SolveMazeStart(&vw, &maze_cells[0][0], MAZE_GRID, MAZE_GRID,
  253. &start_cell, SOL_DIR_RIGHT,
  254. maze_goals, ngoals,
  255. (rand() % 1000) > 500 ? SOL_TURN_LEFT : SOL_TURN_RIGHT,
  256. &sol);
  257. solve_state = SST_MAZE_GROW;
  258. firstMaze = FALSE;
  259. }
  260. /**************************************************************************\
  261. * Step
  262. *
  263. * Main draw proc
  264. *
  265. \**************************************************************************/
  266. static MazeGoal *found_goal = NULL;
  267. static int rot_step;
  268. void Step(void *data)
  269. {
  270. int i;
  271. MazeGoal *goal;
  272. switch(solve_state)
  273. {
  274. case SST_NEW_MAZE:
  275. view_rot = 0;
  276. maze_height = 0.0f;
  277. NewMaze();
  278. break;
  279. case SST_SOLVING:
  280. for (i = 0; i < maze_options.nrats; i++)
  281. {
  282. SolveMazeStep(&rats[i].vw, &rats[i].sol);
  283. UpdateRatPosition(&rats[i]);
  284. }
  285. goal = SolveMazeStep(&vw, &sol);
  286. if (goal == &maze_goals[GOAL_END])
  287. {
  288. solve_state = SST_MAZE_SHRINK;
  289. }
  290. else if (goal != NULL)
  291. {
  292. solve_state = SST_ROTATE;
  293. found_goal = goal;
  294. rot_step = 0;
  295. }
  296. break;
  297. case SST_MAZE_GROW:
  298. maze_height += .025f;
  299. if (maze_height >= 1.0f)
  300. {
  301. solve_state = SST_SOLVING;
  302. }
  303. break;
  304. case SST_MAZE_SHRINK:
  305. maze_height -= .025f;
  306. if (maze_height <= 0.0f)
  307. {
  308. solve_state = SST_NEW_MAZE;
  309. }
  310. break;
  311. case SST_ROTATE:
  312. view_rot += 10.0;
  313. if (++rot_step == 18)
  314. {
  315. Object *sp_obj;
  316. sp_obj = (Object *)found_goal->user;
  317. RemoveObject(sp_obj);
  318. solve_state = SST_SOLVING;
  319. ngoals--;
  320. if (found_goal < maze_goals+ngoals)
  321. {
  322. memmove(found_goal, found_goal+1,
  323. sizeof(MazeGoal)*(size_t)((ULONG_PTR)(ngoals-(found_goal-maze_goals))));
  324. }
  325. SolveMazeSetGoals(&sol, maze_goals, ngoals);
  326. found_goal = NULL;
  327. if (view_rot >= 360.0)
  328. {
  329. view_rot = 0.0;
  330. }
  331. else
  332. {
  333. view_rot = 180.0;
  334. }
  335. }
  336. break;
  337. }
  338. Draw();
  339. for (i = 0; i < MAX_SPECIALS; i++)
  340. {
  341. // Increment rotations of any specials still present in the maze
  342. if (special_obj[i].cell != NULL)
  343. {
  344. special_obj[i].ang = FaAdd(special_obj[i].ang,
  345. FaDeg(special_obj[i].user1));
  346. special_obj[i].user3 += special_obj[i].user2;
  347. }
  348. }
  349. }
  350. void UpdateModes(void)
  351. {
  352. if (maze_options.depth_test)
  353. {
  354. glEnable(GL_DEPTH_TEST);
  355. }
  356. else
  357. {
  358. glDisable(GL_DEPTH_TEST);
  359. }
  360. }
  361. /**************************************************************************\
  362. * Reshape
  363. *
  364. * - called on resize, expose
  365. * - always called on app startup
  366. *
  367. \**************************************************************************/
  368. void
  369. Reshape(int width, int height, void *data )
  370. {
  371. gfAspect = height == 0 ? 1.0f: (float) width / (float) height;
  372. }
  373. /******************************Public*Routine******************************\
  374. * VerifyTextureFiles
  375. *
  376. * Check that any user specified textures are valid
  377. * - MUST be called at ss_Init, or any error msgs will not display properly
  378. *
  379. \**************************************************************************/
  380. void VerifyTextureFiles(void)
  381. {
  382. int i;
  383. ss_DisableTextureErrorMsgs();
  384. for (i = 0; i < NUM_SURFACES; i++) {
  385. if( gTexInfo[i].bTex && !gTexInfo[i].bDefTex ) {
  386. if( !ss_VerifyTextureFile( &gTexInfo[i].texFile ) )
  387. // use default texture
  388. gTexInfo[i].bDefTex = TRUE;
  389. }
  390. }
  391. }
  392. /******************************Public*Routine******************************\
  393. * CalcRep
  394. *
  395. * Figure out repetion based on size.
  396. *
  397. * - Use 128 pixels as a unit repetition reference
  398. * - Size is always a power of 2
  399. *
  400. \**************************************************************************/
  401. static int
  402. CalcRep( int size )
  403. {
  404. double pow2;
  405. int pow2ref = 8;
  406. int rep;
  407. pow2 = log((double)size) / log((double)2.0);
  408. rep = 1 + pow2ref - (int)pow2;
  409. return rep;
  410. }
  411. //mf: tradeoff
  412. #define MAX_TEX_DIM 128
  413. //#define MAX_TEX_DIM 256
  414. /******************************Public*Routine******************************\
  415. * CalcTexRep
  416. *
  417. * Figure out texture repetition based on texture size.
  418. *
  419. * - mf: ? double for walls/ceiling ?
  420. *
  421. \**************************************************************************/
  422. static void
  423. CalcTexRep( TEXTURE *pTex, IPOINT2D *pTexRep )
  424. {
  425. if( pTex->width >= MAX_TEX_DIM )
  426. pTexRep->x = 1;
  427. else
  428. pTexRep->x = CalcRep( pTex->width );
  429. if( pTex->height >= MAX_TEX_DIM )
  430. pTexRep->y = 1;
  431. else
  432. pTexRep->y = CalcRep( pTex->height );
  433. }
  434. /******************************Public*Routine******************************\
  435. * LoadTextures
  436. *
  437. * Load textures from .bmp files or from embedded resources, using
  438. * global texture info structure.
  439. *
  440. * For now, this also sets render modes, since if texturing is off for a
  441. * surface, we always use RENDER_FLAT
  442. *
  443. * History:
  444. * - Nov. 95 [marcfo] : Creation
  445. * - Jan. 96 [marcfo] : Load surface and object textures separately. The 3
  446. * surface textures occupy the first locations of the all_textures[]
  447. * array, and the object textures follow.
  448. *
  449. \**************************************************************************/
  450. static void
  451. LoadTextures(void)
  452. {
  453. int i;
  454. TEXTURE *pTex = all_textures;
  455. TEX_ENV *pTexEnv = gTexEnv;
  456. TEX_RES *pTexRes;
  457. assert( (NUM_SURFACES + NUM_OBJECT_TEXTURES) == NUM_TEXTURES );
  458. // load surface textures (wall, floor, ceiling)
  459. for (i = 0; i < NUM_SURFACES; i++, pTex++, pTexEnv++) {
  460. maze_options.render[i] = RENDER_FLAT;
  461. if( gTexInfo[i].bTex ) {
  462. pTexEnv->pTex = pTex;
  463. pTexEnv->bTransp = FALSE;
  464. // Load user or default texture for the surface
  465. if( !gTexInfo[i].bDefTex &&
  466. ss_LoadTextureFile( &gTexInfo[i].texFile, pTex )) {
  467. } else
  468. {
  469. // Load default resource texture
  470. pTexRes = &gTexResSurf[ gTexInfo[i].iDefTex ];
  471. if( !ss_LoadTextureResource( pTexRes, pTex ) )
  472. continue;
  473. if( ss_PalettedTextureEnabled() &&
  474. (pTexRes->type == TEX_A8) )
  475. {
  476. pTexEnv->bPalRot = TRUE;
  477. pTexEnv->iPalRot = ss_iRand( 0xff );
  478. } else
  479. pTexEnv->bPalRot = FALSE;
  480. }
  481. maze_options.render[i] = RENDER_TEXTURED;
  482. // Figure out texture repetition
  483. CalcTexRep( pTex, &pTexEnv->texRep );
  484. // We would have to set texture parameters per object here,
  485. // but we just use default ones already set by ss_LoadTexture*
  486. }
  487. }
  488. // load object textures
  489. pTexRes = gTexResObject;
  490. for( i = 0; i < NUM_OBJECT_TEXTURES; i++, pTex++, pTexEnv++, pTexRes++ ) {
  491. if( ss_LoadTextureResource( pTexRes, pTex ) )
  492. pTexEnv->pTex = pTex;
  493. else
  494. pTexEnv->pTex = NULL;
  495. pTexEnv->bTransp = FALSE;
  496. // For now we don't do palrot's on any of the object textures
  497. pTexEnv->bPalRot = FALSE;
  498. // No repetition
  499. pTexEnv->texRep.x = pTexEnv->texRep.y = 1;
  500. }
  501. // Set transparency for some of the textures
  502. ss_SetTextureTransparency( gTexEnv[TEX_START].pTex, 0.42f, FALSE );
  503. ss_SetTextureTransparency( gTexEnv[TEX_END].pTex, 0.4f, FALSE );
  504. ss_SetTextureTransparency( gTexEnv[TEX_AD].pTex, 0.4f, FALSE );
  505. #if 0
  506. // Enough already with the transparency!
  507. ss_SetTextureTransparency( &all_textures[TEX_COVER], 0.6f, FALSE );
  508. ss_SetTextureTransparency( &all_textures[TEX_WALL], 0.5f, FALSE );
  509. #endif
  510. // Enable transparency for some of the texture environments
  511. gTexEnv[TEX_START].bTransp = TRUE;
  512. gTexEnv[TEX_END].bTransp = TRUE;
  513. gTexEnv[TEX_AD].bTransp = TRUE;
  514. }
  515. void UseTextureEnv( TEX_ENV *pTexEnv )
  516. {
  517. static HTEXTURE hCurTex = (HTEXTURE) -1;
  518. HTEXTURE hTex = pTexEnv->pTex;
  519. // We cache the current texture for 'no texture object' case
  520. if( !ss_TextureObjectsEnabled() &&
  521. (hCurTex == hTex) )
  522. return; // same texture, no need to send it down
  523. // Make this texture current
  524. ss_SetTexture( hTex );
  525. // Set texture palette if necessary
  526. if( pTexEnv->bPalRot &&
  527. !ss_TextureObjectsEnabled() &&
  528. ss_PalettedTextureEnabled() ) {
  529. // We need to send down the (rotated) palette
  530. ss_SetTexturePalette( hTex, pTexEnv->iPalRot );
  531. }
  532. hCurTex = hTex;
  533. }
  534. /******************************Public*Routine******************************\
  535. * RotateTexturePalettes
  536. *
  537. * If paletted texturing is enabled, go through the supplied list of texture
  538. * environments, and if any have a palette, increment its rotation by the
  539. * supplied iRot value.
  540. *
  541. \**************************************************************************/
  542. void
  543. RotateTexturePalettes( TEX_ENV *pTexEnv, int count, int iRot )
  544. {
  545. int i;
  546. if( !ss_PalettedTextureEnabled() || !pTexEnv )
  547. return;
  548. for( ; count; count--, pTexEnv++ ) {
  549. if( !pTexEnv->pTex || !pTexEnv->pTex->pal )
  550. continue;
  551. if( pTexEnv->bPalRot ) {
  552. // increment palette rotation
  553. pTexEnv->iPalRot += iRot;
  554. if( pTexEnv->iPalRot >= pTexEnv->pTex->pal_size )
  555. pTexEnv->iPalRot = 0;
  556. // Only send down the new palette if texture objects are enabled,
  557. // since otherwise it will be sent down when texture is
  558. // 'made current'
  559. if( ss_TextureObjectsEnabled() ) {
  560. ss_SetTexturePalette( pTexEnv->pTex, pTexEnv->iPalRot );
  561. }
  562. }
  563. }
  564. }
  565. /******************************Public*Routine******************************\
  566. * InitStretchInfo
  567. *
  568. \**************************************************************************/
  569. static void
  570. InitStretchInfo( STRETCH_INFO *pStretch )
  571. {
  572. ISIZE screen;
  573. pStretch->baseWidth = 320;
  574. pStretch->baseHeight = 200;
  575. pStretch->bRatioMode = FALSE;
  576. }
  577. /******************************Public*Routine******************************\
  578. * SetFloaterInfo
  579. *
  580. * Set the size and position of the floating child window
  581. *
  582. \**************************************************************************/
  583. static void
  584. SetFloaterInfo( ISIZE *pParentSize, CHILD_INFO *pChild )
  585. {
  586. float hdtvAspect = 9.0f / 16.0f;
  587. ISIZE *pChildSize = &pChild->size;
  588. // Set width according to user-specified size
  589. // (giSize range is 0..100)
  590. // set min size as 1/3 parent width
  591. pChildSize->width =
  592. (int) ((0.333f + 2.0f*giSize/300.0f) * pParentSize->width);
  593. // Scale height for hdtv aspect ratio
  594. pChildSize->height = (int) (hdtvAspect * pChildSize->width + 0.5f);
  595. // Ensure height not too big
  596. SS_CLAMP_TO_RANGE2( pChildSize->height, 0, pParentSize->height );
  597. pChild->pos.x = (pParentSize->width - pChildSize->width) / 2;
  598. pChild->pos.y = (pParentSize->height - pChildSize->height) / 2;
  599. }
  600. /******************************Public*Routine******************************\
  601. * ss_Init
  602. *
  603. * Initialize - called on first entry into ss.
  604. * Called BEFORE gl is initialized!
  605. * Just do basic stuff here, like set up callbacks, verify dialog stuff, etc.
  606. *
  607. * Fills global SSContext structure with required data, and returns ptr
  608. * to it.
  609. *
  610. \**************************************************************************/
  611. SSContext *
  612. ss_Init( void )
  613. {
  614. getIniSettings();
  615. VerifyTextureFiles();
  616. // Set callbacks
  617. ss_InitFunc( maze_Init );
  618. ss_UpdateFunc( Step );
  619. ss_ReshapeFunc( Reshape );
  620. gssc.depthType = (maze_options.depth_test) ? SS_DEPTH16 : SS_DEPTH_NONE;
  621. // Currently stretch and floater mutex
  622. gssc.bDoubleBuf = TRUE; // will get turned off if stretch used
  623. if( gbTurboMode ) {
  624. // We stretch out the drawing area to the full size of the main window
  625. gssc.bFloater = FALSE;
  626. gssc.bStretch = TRUE;
  627. InitStretchInfo( &gssc.stretchInfo );
  628. } else {
  629. // A static centered floating window is created in the main window
  630. FLOATER_INFO *pFloater = &gssc.floaterInfo;
  631. gssc.bFloater = TRUE;
  632. gssc.bStretch = FALSE;
  633. pFloater->bMotion = FALSE;
  634. pFloater->ChildSizeFunc = SetFloaterInfo;
  635. }
  636. return &gssc;
  637. }
  638. /******************************Public*Routine******************************\
  639. * maze_Init
  640. *
  641. * Initializes OpenGL state
  642. *
  643. \**************************************************************************/
  644. void
  645. maze_Init( void *data )
  646. {
  647. float fv4[4];
  648. if (!FxInitialize(FA_TABLE_SIZE, 0))
  649. {
  650. printf("FxInit failed\n");
  651. exit(1);
  652. }
  653. glShadeModel( GL_FLAT );
  654. glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  655. glClearDepth(1);
  656. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  657. glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
  658. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  659. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  660. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  661. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  662. glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
  663. if( (giImageQual == IMAGEQUAL_DEFAULT) || gbTurboMode ) {
  664. maze_options.bDither = FALSE;
  665. glDisable( GL_DITHER );
  666. } else {
  667. maze_options.bDither = TRUE;
  668. glEnable( GL_DITHER );
  669. }
  670. // Load textures and set render modes
  671. LoadTextures();
  672. fv4[0] = MAZE_SIZE/2.0f;
  673. fv4[1] = MAZE_SIZE/2.0f;
  674. fv4[2] = 10.0f;
  675. fv4[3] = 1.0f;
  676. glLightfv(GL_LIGHT0, GL_POSITION, fv4);
  677. glEnable(GL_LIGHT0);
  678. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  679. // Check which texture environment function to use for objects
  680. if( ss_fOnGL11() )
  681. gTexEnvMode = GL_REPLACE;
  682. else
  683. gTexEnvMode = GL_MODULATE;
  684. maze_walls_list = glGenLists(1);
  685. UpdateModes();
  686. }