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.

776 lines
17 KiB

  1. #include <windows.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <GL/glu.h>
  5. /*
  6. #ifdef X11
  7. #include <GL/glx.h>
  8. extern "C" {
  9. #include <tk.h>
  10. };
  11. #endif
  12. */
  13. #ifdef WIN32
  14. #include "stonehen.h"
  15. #endif
  16. #include "Point.h"
  17. #include "Ring.h"
  18. #include "Roundwal.h"
  19. #include "Ellipse.h"
  20. #include "Telescop.h"
  21. #define SCENE_EXTERN
  22. #include "scene.h"
  23. GLfloat mat_view[16];
  24. GLfloat view_rotx = 0;
  25. GLfloat fov = 45.0, aspect = 1.0;
  26. static Point eyep = {0, 0, .5};
  27. static Point lookp = {0.05, 1, .25};
  28. TimeDate current_time;
  29. static int list_ground;
  30. static int list_texture_ground;
  31. static int list_trees;
  32. static int list_texture_trees;
  33. static int list_ring;
  34. static int list_ellipse;
  35. static int list_texture_stones;
  36. static int list_shadows;
  37. static int list_telescope;
  38. static int list_texture_telescope;
  39. int draw_ground = 1;
  40. int draw_trees = 0;
  41. int draw_ring = 1;
  42. int draw_ellipse = 1;
  43. int draw_shadows = 0;
  44. int use_lighting = 1;
  45. int use_textures = 0;
  46. int texture_hack = 0; //HACK HACK HACK - only texture map the stone
  47. int use_normal_fog = 0;
  48. int use_fancy_fog = 0;
  49. int use_telescope = 0;
  50. int use_antialias = 0;
  51. static void scene_identity();
  52. static void scene_project(GLfloat f = fov, float dx = 0, float dy = 0);
  53. static void scene_draw(int rend = 1);
  54. static void scene_render_telescope();
  55. static void draw_background();
  56. Point sun_position = {0., .707, .707, 0.};
  57. Color ambient(.25, .25, .25, 1.);
  58. static void lights_init();
  59. static void lists_init();
  60. static void ground_list_init();
  61. static void ground_draw();
  62. Roundwall trees;
  63. static void trees_list_init();
  64. static void trees_draw();
  65. Ring ring;
  66. static void ring_list_init();
  67. static void ring_draw();
  68. EllipseSt ellipse;
  69. static void ellipse_list_init();
  70. static void ellipse_draw();
  71. static void shadows_list_init();
  72. static void shadows_draw();
  73. Weather weather;
  74. Telescope telescope;
  75. GLfloat magnif = .5;
  76. static void telescope_list_init();
  77. static void telescope_draw();
  78. /* Read the back buffer into the accum buffer, adding in the appropriate
  79. * alpha values */
  80. static void fog_read_image();
  81. /* Add the accum buffer to the back buffer */
  82. static void fog_write_image();
  83. inline float clamp(float x, float min, float max)
  84. {
  85. if (x < min) return min;
  86. else if (x > max) return max;
  87. else return x;
  88. }
  89. void scene_init()
  90. {
  91. scene_identity();
  92. scene_viewer_center();
  93. glEnable(GL_CULL_FACE);
  94. glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
  95. glEnable(GL_NORMALIZE);
  96. /* Initial time will be four in the afternoon */
  97. scene_set_time(TimeDate(16, 0));
  98. scene_set_weather(weathers[def_weather_index]);
  99. lights_init();
  100. lists_init();
  101. }
  102. inline double time_minutes(int hour, int minute, int second)
  103. {
  104. return (double)hour*60.0 + (double)minute + (double)second / 60.0;
  105. }
  106. static void scene_time_changed()
  107. {
  108. sun_position = current_time.sun_direction();
  109. weather.apply(sun_position);
  110. lights_init();
  111. shadows_list_init();
  112. }
  113. void scene_set_time(TimeDate t)
  114. {
  115. current_time = t;
  116. scene_time_changed();
  117. }
  118. void scene_inc_time(TimeDate t)
  119. {
  120. current_time += t;
  121. scene_time_changed();
  122. }
  123. /* This is a hack -- has to be called several times to get the antialiasing
  124. * to work */
  125. static void scene_inner_render(GLfloat dx = 0, GLfloat dy = 0)
  126. {
  127. /* This draws layered fog if the use_fancy_fog flag is on --
  128. * it's going to be slow on anything but high-end stuff */
  129. if (use_fancy_fog && weather.fog_density != 0.) {
  130. glMatrixMode(GL_PROJECTION);
  131. glLoadIdentity();
  132. glMatrixMode(GL_MODELVIEW);
  133. glLoadIdentity();
  134. glEnable(GL_FOG);
  135. draw_background();
  136. scene_project(fov, dx, dy);
  137. glClear(GL_DEPTH_BUFFER_BIT);
  138. if (use_lighting) glEnable(GL_LIGHTING);
  139. scene_draw();
  140. if (use_lighting) glDisable(GL_LIGHTING);
  141. fog_read_image();
  142. glDisable(GL_FOG);
  143. } else
  144. if (use_normal_fog && weather.fog_density != 0.) glEnable(GL_FOG);
  145. else glDisable(GL_FOG);
  146. glMatrixMode(GL_PROJECTION);
  147. glLoadIdentity();
  148. glMatrixMode(GL_MODELVIEW);
  149. glLoadIdentity();
  150. /* This is the part where we actually draw the image */
  151. glClear(GL_DEPTH_BUFFER_BIT);
  152. draw_background();
  153. scene_project(fov, dx, dy);
  154. glClear(GL_DEPTH_BUFFER_BIT);
  155. if (use_lighting) glEnable(GL_LIGHTING);
  156. scene_draw();
  157. if (use_lighting) glDisable(GL_LIGHTING);
  158. if (use_fancy_fog && weather.fog_density != 0.) {
  159. fog_write_image();
  160. }
  161. if (use_telescope) scene_render_telescope();
  162. }
  163. void scene_render()
  164. {
  165. GLint vp[4];
  166. scene_inner_render();
  167. if (!use_antialias) return;
  168. if (use_fancy_fog) {
  169. fprintf(stderr, "Cannot antialias while using fancy fog.\n");
  170. return;
  171. }
  172. glGetIntegerv(GL_VIEWPORT, vp);
  173. glAccum(GL_LOAD, .5);
  174. scene_inner_render(2. / (float)vp[2], 2. / (float)vp[3]);
  175. glAccum(GL_ACCUM, .5);
  176. /*
  177. scene_inner_render(-2. / (float)vp[2], -2. / (float)vp[3]);
  178. glAccum(GL_ACCUM, .25);
  179. */
  180. glAccum(GL_RETURN, 1);
  181. /*
  182. glDrawBuffer(GL_BACK);
  183. glFlush();
  184. */
  185. }
  186. static void scene_render_telescope()
  187. {
  188. telescope.draw_setup(fov, aspect);
  189. /* Don't fog the telescope - moisture makes it rust.
  190. * Seriously, it's in a strange coordinate system and fog will look
  191. * bad on it. */
  192. glPushAttrib(GL_ENABLE_BIT);
  193. glDisable(GL_FOG);
  194. if (use_textures) {
  195. glCallList(list_texture_telescope);
  196. glEnable(GL_TEXTURE_2D);
  197. }
  198. glCallList(list_telescope);
  199. glPopAttrib();
  200. if (use_lighting) glEnable(GL_LIGHTING);
  201. glEnable(GL_STENCIL_TEST);
  202. glClearStencil(0);
  203. glClear(GL_STENCIL_BUFFER_BIT);
  204. glStencilFunc(GL_ALWAYS, 0x1, 0x1);
  205. glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
  206. glDisable(GL_CULL_FACE);
  207. telescope.draw_lens();
  208. glEnable(GL_CULL_FACE);
  209. telescope.draw_takedown();
  210. if (use_lighting) glDisable(GL_LIGHTING);
  211. glStencilFunc(GL_NOTEQUAL, 0x0, 0xffffffff);
  212. glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
  213. scene_identity();
  214. draw_background();
  215. glMatrixMode(GL_PROJECTION);
  216. glTranslatef(telescope.xpos / magnif, -telescope.ypos / magnif, 0);
  217. scene_project(fov * magnif);
  218. glClear(GL_DEPTH_BUFFER_BIT);
  219. /* Pushing the lighting bit used to do really bad things, but
  220. * hopefully they've all gone away */
  221. glPushAttrib(GL_LIGHTING_BIT);
  222. lights_init();
  223. if (use_lighting) glEnable(GL_LIGHTING);
  224. scene_draw();
  225. if (use_lighting) glDisable(GL_LIGHTING);
  226. glPopAttrib();
  227. glDisable(GL_STENCIL_TEST);
  228. }
  229. static void scene_identity()
  230. {
  231. glMatrixMode(GL_PROJECTION);
  232. glLoadIdentity();
  233. glMatrixMode(GL_MODELVIEW);
  234. glLoadIdentity();
  235. }
  236. static void scene_project(GLfloat f, float dx, float dy)
  237. {
  238. glMatrixMode(GL_PROJECTION);
  239. glOrtho(-1 - dx, 1, -1 - dy, 1, 0, -1);
  240. gluPerspective(f, aspect, 0.01, 40.0);
  241. glMatrixMode(GL_MODELVIEW);
  242. glRotatef(view_rotx, 1, 0, 0);
  243. gluLookAt(eyep.pt[0], eyep.pt[1], eyep.pt[2],
  244. lookp.pt[0], lookp.pt[1], lookp.pt[2],
  245. 0, 0, 1);
  246. glMultMatrixf(mat_view);
  247. lights_init();
  248. }
  249. /* scene_draw() just draws the geometry - it's used for rendering and
  250. * picking. */
  251. static void scene_draw(int rend)
  252. {
  253. if (draw_ground) {
  254. if (rend) {
  255. if (use_textures) {
  256. glCallList(list_texture_ground);
  257. glEnable(GL_TEXTURE_2D);
  258. } else glEnable(GL_COLOR_MATERIAL);
  259. }
  260. glCallList(list_ground);
  261. if (rend) {
  262. glDisable(GL_TEXTURE_2D);
  263. glDisable(GL_COLOR_MATERIAL);
  264. }
  265. }
  266. if (draw_shadows) {
  267. if (use_textures && rend && !draw_ground) {
  268. glCallList(list_texture_ground);
  269. glEnable(GL_TEXTURE_2D);
  270. }
  271. glCallList(list_shadows);
  272. if (use_textures && rend) glDisable(GL_TEXTURE_2D);
  273. }
  274. if (draw_trees) {
  275. if (use_textures && rend) {
  276. glCallList(list_texture_trees);
  277. glEnable(GL_TEXTURE_2D);
  278. }
  279. glCallList(list_trees);
  280. if (use_textures && rend) glDisable(GL_TEXTURE_2D);
  281. }
  282. glClear(GL_DEPTH_BUFFER_BIT);
  283. if (draw_ring) {
  284. if (rend) {
  285. if (use_textures || texture_hack) {
  286. glCallList(list_texture_stones);
  287. glEnable(GL_TEXTURE_2D);
  288. }
  289. glEnable(GL_COLOR_MATERIAL);
  290. glColor3f(.5, .5, .5);
  291. }
  292. glCallList(list_ring);
  293. if (rend) {
  294. if (use_textures || texture_hack) glDisable(GL_TEXTURE_2D);
  295. glDisable(GL_COLOR_MATERIAL);
  296. }
  297. }
  298. if (draw_ellipse) {
  299. if (use_textures && rend) {
  300. // Hack to avoid doing something expensive twice in a row
  301. if (!draw_ring) glCallList(list_texture_stones);
  302. glEnable(GL_TEXTURE_2D);
  303. }
  304. glCallList(list_ellipse);
  305. if (use_textures && rend) glDisable(GL_TEXTURE_2D);
  306. }
  307. }
  308. static void draw_background()
  309. {
  310. weather.draw_sky(sun_position);
  311. }
  312. void scene_viewer_center()
  313. {
  314. glPushMatrix();
  315. glLoadIdentity();
  316. glGetFloatv(GL_MODELVIEW_MATRIX, mat_view);
  317. glPopMatrix();
  318. view_rotx = 0;
  319. }
  320. void scene_viewer_rotate_worldz(GLfloat degrees)
  321. {
  322. glMatrixMode(GL_MODELVIEW);
  323. glPushMatrix();
  324. glLoadIdentity();
  325. glRotatef(degrees, 0, 0, 1);
  326. glMultMatrixf(mat_view);
  327. glGetFloatv(GL_MODELVIEW_MATRIX, mat_view);
  328. glPopMatrix();
  329. glMatrixMode(GL_MODELVIEW);
  330. }
  331. void scene_viewer_rotatez(GLfloat degrees)
  332. {
  333. glMatrixMode(GL_PROJECTION);
  334. glPushMatrix();
  335. glLoadIdentity();
  336. glRotatef(degrees, 0, 0, 1);
  337. glMultMatrixf(mat_view);
  338. glGetFloatv(GL_PROJECTION_MATRIX, mat_view);
  339. glPopMatrix();
  340. glMatrixMode(GL_MODELVIEW);
  341. }
  342. void scene_viewer_rotatex(GLfloat degrees)
  343. {
  344. view_rotx += degrees;
  345. view_rotx = clamp(view_rotx, -60, 60);
  346. scene_identity();
  347. scene_project();
  348. lights_init();
  349. }
  350. void scene_viewer_translate(GLfloat dist)
  351. {
  352. glMatrixMode(GL_PROJECTION);
  353. glPushMatrix();
  354. glLoadIdentity();
  355. glTranslatef(0, dist, 0);
  356. glMultMatrixf(mat_view);
  357. glGetFloatv(GL_PROJECTION_MATRIX, mat_view);
  358. glPopMatrix();
  359. glMatrixMode(GL_MODELVIEW);
  360. scene_identity();
  361. scene_project();
  362. lights_init();
  363. }
  364. void scene_position_telescope(GLfloat x, GLfloat y)
  365. {
  366. telescope.xpos = x;
  367. telescope.ypos = y;
  368. }
  369. void scene_get_position_telescope(GLfloat *x, GLfloat *y)
  370. {
  371. *x = telescope.xpos;
  372. *y = telescope.ypos;
  373. }
  374. void scene_get_radius_telescope(GLfloat *r)
  375. {
  376. *r = telescope.get_radius();
  377. }
  378. void scene_set_weather(Weather w)
  379. {
  380. weather = w;
  381. weather.apply(sun_position);
  382. shadows_list_init();
  383. }
  384. static int get_lists(int size)
  385. {
  386. int i;
  387. i = glGenLists(size);
  388. if (size && !i) {
  389. fprintf(stderr, "Unable to allocate %d display lists.\n");
  390. exit(1);
  391. }
  392. return i;
  393. }
  394. static void lights_init()
  395. {
  396. glLightfv(GL_LIGHT0, GL_POSITION, sun_position.pt);
  397. /* This light gives a diffuse coefficient when the sun is off -
  398. * it's used for drawing shadows */
  399. glLightfv(GL_LIGHT1, GL_AMBIENT, black.c);
  400. glLightfv(GL_LIGHT1, GL_DIFFUSE, black.c);
  401. glLightfv(GL_LIGHT1, GL_SPECULAR, black.c);
  402. }
  403. #ifdef TEXTURE
  404. static void textures_list_init()
  405. {
  406. TK_RGBImageRec *teximage = NULL;
  407. teximage = tkRGBImageLoad((char *)texfile_stones);
  408. glNewList(list_texture_stones, GL_COMPILE);
  409. gluBuild2DMipmaps(GL_TEXTURE_2D, 3, teximage->sizeX, teximage->sizeY,
  410. GL_RGB, GL_UNSIGNED_BYTE, teximage->data);
  411. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
  412. GL_NEAREST_MIPMAP_NEAREST);
  413. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
  414. GL_LINEAR);
  415. glMatrixMode(GL_TEXTURE);
  416. glLoadIdentity();
  417. glMatrixMode(GL_MODELVIEW);
  418. glDisable(GL_TEXTURE_GEN_S);
  419. glDisable(GL_TEXTURE_GEN_T);
  420. glEndList();
  421. /* tk is obnoxious and doesn't seem to provide any mechanism for this */
  422. free(teximage->data);
  423. free(teximage);
  424. teximage = tkRGBImageLoad((char *)texfile_ground);
  425. glNewList(list_texture_ground, GL_COMPILE);
  426. gluBuild2DMipmaps(GL_TEXTURE_2D, 3, teximage->sizeX, teximage->sizeY,
  427. GL_RGB, GL_UNSIGNED_BYTE, teximage->data);
  428. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
  429. GL_NEAREST_MIPMAP_NEAREST);
  430. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
  431. GL_LINEAR);
  432. glMatrixMode(GL_TEXTURE);
  433. glLoadIdentity();
  434. glScalef(100, 100, 1);
  435. glMatrixMode(GL_MODELVIEW);
  436. glDisable(GL_TEXTURE_GEN_S);
  437. glDisable(GL_TEXTURE_GEN_T);
  438. glEndList();
  439. free(teximage->data);
  440. free(teximage);
  441. /* Figure out some way to get an alpha component out of the tk --
  442. * otherwise we're really hosed */
  443. teximage = tkRGBImageLoad((char *)texfile_trees);
  444. glNewList(list_texture_trees, GL_COMPILE);
  445. /* In the final scenerio we probably won't want to mipmap this, but it's
  446. * not square and I don't feel like bothering to scale it */
  447. gluBuild2DMipmaps(GL_TEXTURE_2D, 3, teximage->sizeX, teximage->sizeY,
  448. GL_RGB, GL_UNSIGNED_BYTE, teximage->data);
  449. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
  450. GL_NEAREST_MIPMAP_NEAREST);
  451. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
  452. GL_LINEAR);
  453. glMatrixMode(GL_TEXTURE);
  454. glLoadIdentity();
  455. glMatrixMode(GL_MODELVIEW);
  456. glDisable(GL_TEXTURE_GEN_S);
  457. glDisable(GL_TEXTURE_GEN_T);
  458. glEndList();
  459. free(teximage->data);
  460. free(teximage);
  461. teximage = tkRGBImageLoad((char *)texfile_telescope);
  462. glNewList(list_texture_telescope, GL_COMPILE);
  463. glTexImage2D(GL_TEXTURE_2D, 0, 3, teximage->sizeX, teximage->sizeY,
  464. 0, GL_RGB, GL_UNSIGNED_BYTE, teximage->data);
  465. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  466. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  467. glMatrixMode(GL_TEXTURE);
  468. glLoadIdentity();
  469. glMatrixMode(GL_MODELVIEW);
  470. glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
  471. glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
  472. glEnable(GL_TEXTURE_GEN_S);
  473. glEnable(GL_TEXTURE_GEN_T);
  474. glEndList();
  475. free(teximage->data);
  476. free(teximage);
  477. }
  478. #endif
  479. static void lists_init()
  480. {
  481. list_ground = get_lists(1);
  482. list_texture_ground = get_lists(1);
  483. list_trees = get_lists(1);
  484. list_texture_trees = get_lists(1);
  485. list_ring = get_lists(1);
  486. list_ellipse = get_lists(1);
  487. list_texture_stones = get_lists(1);
  488. list_shadows = get_lists(1);
  489. list_telescope = get_lists(1);
  490. list_texture_telescope = get_lists(1);
  491. ground_list_init();
  492. trees_list_init();
  493. shadows_list_init();
  494. ring_list_init();
  495. ellipse_list_init();
  496. #ifdef TEXTURE
  497. textures_list_init();
  498. #endif
  499. telescope_list_init();
  500. }
  501. static void ground_list_init()
  502. {
  503. glNewList(list_ground, GL_COMPILE);
  504. ground_draw();
  505. glEndList();
  506. }
  507. static void ground_draw()
  508. {
  509. glColor3f(0, .75, 0);
  510. glLoadName(name_ground);
  511. glNormal3f(0, 0, 1);
  512. glPushMatrix();
  513. /* Making something this big would confuse the zbuffer, but we're
  514. * clearing that AFTER drawing this, so it's ok */
  515. glScalef(100, 100, 1);
  516. glBegin(GL_QUADS);
  517. glTexCoord2f(0, 0);
  518. glVertex2f(-1, -1);
  519. glTexCoord2f(1, 0);
  520. glVertex2f(1, -1);
  521. glTexCoord2f(1, 1);
  522. glVertex2f(1, 1);
  523. glTexCoord2f(0, 1);
  524. glVertex2f(-1, 1);
  525. glEnd();
  526. glPopMatrix();
  527. }
  528. static void trees_list_init()
  529. {
  530. glNewList(list_trees, GL_COMPILE);
  531. trees_draw();
  532. glEndList();
  533. }
  534. static void trees_draw()
  535. {
  536. glEnable(GL_COLOR_MATERIAL);
  537. glColor3f(0, .5, 0);
  538. glLoadName(name_trees);
  539. glEnable(GL_BLEND);
  540. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  541. trees.draw();
  542. glDisable(GL_BLEND);
  543. glDisable(GL_COLOR_MATERIAL);
  544. }
  545. static void ring_list_init()
  546. {
  547. glNewList(list_ring, GL_COMPILE);
  548. ring_draw();
  549. glEndList();
  550. }
  551. static void ring_draw()
  552. {
  553. glLoadName(name_ring);
  554. glEnable(GL_DEPTH_TEST);
  555. ring.erode(.1);
  556. ring.draw();
  557. glDisable(GL_DEPTH_TEST);
  558. }
  559. static void ellipse_list_init()
  560. {
  561. glNewList(list_ellipse, GL_COMPILE);
  562. ellipse_draw();
  563. glEndList();
  564. }
  565. static void ellipse_draw()
  566. {
  567. glEnable(GL_COLOR_MATERIAL);
  568. glColor3f(.5, .5, .5);
  569. glEnable(GL_DEPTH_TEST);
  570. glLoadName(name_ellipse);
  571. ellipse.erode(.1);
  572. ellipse.draw();
  573. glDisable(GL_DEPTH_TEST);
  574. glDisable(GL_COLOR_MATERIAL);
  575. }
  576. static void shadows_list_init()
  577. {
  578. glNewList(list_shadows, GL_COMPILE);
  579. shadows_draw();
  580. glEndList();
  581. }
  582. static void shadows_draw()
  583. {
  584. Color grass(0, .75, 0);
  585. glPushAttrib(GL_ENABLE_BIT);
  586. /* Turn the sun off */
  587. glDisable(GL_LIGHT0);
  588. glEnable(GL_LIGHT1);
  589. glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, grass.c);
  590. glColor3fv((grass * .5).c);
  591. glDisable(GL_CULL_FACE);
  592. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  593. glEnable(GL_BLEND);
  594. ring.draw_shadow(sun_position, weather.shadow_blur(),
  595. grass * .5, grass);
  596. ellipse.draw_shadow(sun_position, weather.shadow_blur(),
  597. grass * .5, grass);
  598. glPopAttrib();
  599. }
  600. static void telescope_list_init()
  601. {
  602. glNewList(list_telescope, GL_COMPILE);
  603. telescope_draw();
  604. glEndList();
  605. }
  606. static void telescope_draw()
  607. {
  608. glLoadName(name_telescope);
  609. glEnable(GL_COLOR_MATERIAL);
  610. glDisable(GL_CULL_FACE);
  611. glClear(GL_DEPTH_BUFFER_BIT);
  612. glEnable(GL_DEPTH_TEST);
  613. telescope.draw_body();
  614. glDisable(GL_DEPTH_TEST);
  615. glEnable(GL_CULL_FACE);
  616. glDisable(GL_COLOR_MATERIAL);
  617. }
  618. static void fog_read_image()
  619. {
  620. glPushMatrix();
  621. glLoadIdentity();
  622. /* This creates an alpha gradient across the image */
  623. /* glColorMask(0, 0, 0, 1);
  624. glBegin(GL_QUADS);
  625. glColor4f(1, 1, 1, 1);
  626. glVertex2f(-1, -1);
  627. glVertex2f(1, -1);
  628. glColor4f(1, 1, 1, 0);
  629. glVertex2f(1, 1);
  630. glVertex2f(-1, 1);
  631. glEnd();
  632. glColorMask(1, 1, 1, 1);
  633. */
  634. glDrawBuffer(GL_BACK);
  635. glReadBuffer(GL_BACK);
  636. glAccum(GL_LOAD, 1);
  637. glPopMatrix();
  638. }
  639. static void fog_write_image()
  640. {
  641. glDrawBuffer(GL_BACK);
  642. /* Put this back in once we're done testing */
  643. // glEnable(GL_BLEND);
  644. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  645. glAccum(GL_RETURN, 1);
  646. glDisable(GL_BLEND);
  647. }