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.

787 lines
18 KiB

  1. #include <windows.h>
  2. #include <GL/glu.h>
  3. #ifdef X11
  4. #include <GL/glx.h>
  5. #endif
  6. #include <math.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #ifdef WIN32
  10. #include "stonehen.h"
  11. #endif
  12. #include "Stone.h"
  13. const GLfloat root2 = 1.4142136;
  14. const GLfloat root3 = sqrt(3.);
  15. const GLfloat rt_half = .70710678;
  16. inline float radians(float a) {return M_PI * a / 180.0; }
  17. inline float sign(float a) {return (a > 0. ? 1 : (a < 0. ? -1 : 0)); }
  18. Stone::Stone()
  19. {
  20. translation.set(0, 0, 0);
  21. rotation = 0;
  22. dimensions.set(1, 1, 1);
  23. erosion = 0;
  24. points_valid = transforms_valid = 0;
  25. }
  26. Stone::~Stone()
  27. {
  28. }
  29. Stone Stone::operator=(Stone a)
  30. {
  31. int i;
  32. translation = a.translation;
  33. rotation = a.rotation;
  34. dimensions = a.dimensions;
  35. erosion = a.erosion;
  36. if (a.points_valid && a.transforms_valid) {
  37. for (i = 0; i < 24; i++) points[i] = a.points[i];
  38. points_valid = transforms_valid = 1;
  39. } else points_valid = transforms_valid = 0;
  40. return *this;
  41. }
  42. void Stone::set_dimensions(GLfloat x, GLfloat y, GLfloat z)
  43. {
  44. dimensions.set(x, y, z);
  45. points_valid = 0;
  46. }
  47. void Stone::set_dimensions(Point p)
  48. {
  49. dimensions = p;
  50. points_valid = 0;
  51. }
  52. void Stone::erode(float p)
  53. {
  54. erosion += p;
  55. points_valid = 0;
  56. }
  57. void Stone::translate(GLfloat x, GLfloat y, GLfloat z)
  58. {
  59. translation.pt[0] += x;
  60. translation.pt[1] += y;
  61. translation.pt[2] += z;
  62. points_valid = 0;
  63. }
  64. void Stone::translate(Point p)
  65. {
  66. translation += p;
  67. points_valid = 0;
  68. }
  69. void Stone::rotate_self_aboutz(GLfloat angle)
  70. {
  71. rotation += angle;
  72. points_valid = 0;
  73. }
  74. void Stone::draw()
  75. {
  76. compute_points();
  77. glPushMatrix();
  78. glRotatef(rotation, 0, 0, 1);
  79. glTranslatef(translation.pt[0], translation.pt[1], translation.pt[2]);
  80. glScalef(dimensions.pt[0], dimensions.pt[1], dimensions.pt[2]);
  81. draw_faces();
  82. draw_edges();
  83. draw_corners();
  84. glPopMatrix();
  85. }
  86. void Stone::compute_points()
  87. {
  88. GLfloat e = 1.0 - erosion;
  89. if (points_valid) return;
  90. points[0].set(1, e, e);
  91. points[1].set(e, 1, e);
  92. points[2].set(e, e, 1);
  93. points[3].set(-e, e, 1);
  94. points[4].set(-e, 1, e);
  95. points[5].set(-1, e, e);
  96. points[6].set(e, -e, 1);
  97. points[7].set(e, -1, e);
  98. points[8].set(1, -e, e);
  99. points[9 ].set(e, e, -1);
  100. points[10].set(e, 1, -e);
  101. points[11].set(1, e, -e);
  102. points[12].set(-1, -e, e);
  103. points[13].set(-e, -1, e);
  104. points[14].set(-e, -e, 1);
  105. points[15].set(1, -e, -e);
  106. points[16].set(e, -1, -e);
  107. points[17].set(e, -e, -1);
  108. points[18].set(-1, e, -e);
  109. points[19].set(-e, 1, -e);
  110. points[20].set(-e, e, -1);
  111. points[21].set(-e, -e, -1);
  112. points[22].set(-e, -1, -e);
  113. points[23].set(-1, -e, -e);
  114. points_valid = 1;
  115. transforms_valid = 0;
  116. }
  117. inline Point Stone::trans_rot_point(Point p, float c, float s)
  118. {
  119. Point val;
  120. val = p + translation;
  121. val = val.rotate_aboutz(c, s);
  122. return val;
  123. }
  124. inline Point Stone::transform_point(Point p, float c, float s)
  125. {
  126. Point val;
  127. val = p.scale(dimensions);
  128. val += translation;
  129. val = val.rotate_aboutz(c, s);
  130. return val;
  131. }
  132. void Stone::transform_points()
  133. {
  134. float c, s;
  135. int i;
  136. if (points_valid && transforms_valid) return;
  137. points_valid = 0;
  138. compute_points();
  139. c = cos(radians(rotation));
  140. s = sin(radians(rotation));
  141. for (i = 0; i < 24; i++) points[i] = transform_point(points[i], c, s);
  142. points_valid = 0;
  143. transforms_valid = 1;
  144. }
  145. void Stone::draw_faces(int flat)
  146. {
  147. draw_faces(points, flat);
  148. }
  149. void Stone::draw_faces(Point *p, int flat)
  150. {
  151. glBegin(GL_QUADS);
  152. glNormal3f(1, 0, 0);
  153. if (flat) glTexCoord2fv(p[15].pt);
  154. else glTexCoord2f(0, 0);
  155. glVertex3fv(p[15].pt);
  156. if (flat) glTexCoord2fv(p[11].pt);
  157. else glTexCoord2f(1, 0);
  158. glVertex3fv(p[11].pt);
  159. if (flat) glTexCoord2fv(p[0].pt);
  160. else glTexCoord2f(1, 1);
  161. glVertex3fv(p[0].pt);
  162. if (flat) glTexCoord2fv(p[8].pt);
  163. else glTexCoord2f(0, 1);
  164. glVertex3fv(p[8].pt);
  165. glNormal3f(-1, 0, 0);
  166. if (flat) glTexCoord2fv(p[12].pt);
  167. else glTexCoord2f(0, 0);
  168. glVertex3fv(p[12].pt);
  169. if (flat) glTexCoord2fv(p[5].pt);
  170. else glTexCoord2f(1, 0);
  171. glVertex3fv(p[5].pt);
  172. if (flat) glTexCoord2fv(p[18].pt);
  173. else glTexCoord2f(1, 1);
  174. glVertex3fv(p[18].pt);
  175. if (flat) glTexCoord2fv(p[23].pt);
  176. else glTexCoord2f(0, 1);
  177. glVertex3fv(p[23].pt);
  178. glNormal3f(0, 1, 0);
  179. if (flat) glTexCoord2fv(p[4].pt);
  180. else glTexCoord2f(0, 0);
  181. glVertex3fv(p[4].pt);
  182. if (flat) glTexCoord2fv(p[1].pt);
  183. else glTexCoord2f(1, 0);
  184. glVertex3fv(p[1].pt);
  185. if (flat) glTexCoord2fv(p[10].pt);
  186. else glTexCoord2f(1, 1);
  187. glVertex3fv(p[10].pt);
  188. if (flat) glTexCoord2fv(p[19].pt);
  189. else glTexCoord2f(0, 1);
  190. glVertex3fv(p[19].pt);
  191. glNormal3f(0, -1, 0);
  192. if (flat) glTexCoord2fv(p[22].pt);
  193. else glTexCoord2f(0, 0);
  194. glVertex3fv(p[22].pt);
  195. if (flat) glTexCoord2fv(p[16].pt);
  196. else glTexCoord2f(1, 0);
  197. glVertex3fv(p[16].pt);
  198. if (flat) glTexCoord2fv(p[7].pt);
  199. else glTexCoord2f(1, 1);
  200. glVertex3fv(p[7].pt);
  201. if (flat) glTexCoord2fv(p[13].pt);
  202. else glTexCoord2f(0, 1);
  203. glVertex3fv(p[13].pt);
  204. glNormal3f(0, 0, 1);
  205. if (flat) glTexCoord2fv(p[14].pt);
  206. else glTexCoord2f(0, 0);
  207. glVertex3fv(p[14].pt);
  208. if (flat) glTexCoord2fv(p[6].pt);
  209. else glTexCoord2f(1, 0);
  210. glVertex3fv(p[6].pt);
  211. if (flat) glTexCoord2fv(p[2].pt);
  212. else glTexCoord2f(1, 1);
  213. glVertex3fv(p[2].pt);
  214. if (flat) glTexCoord2fv(p[3].pt);
  215. else glTexCoord2f(0, 1);
  216. glVertex3fv(p[3].pt);
  217. glNormal3f(0, 0, -1);
  218. if (flat) glTexCoord2fv(p[20].pt);
  219. else glTexCoord2f(0, 0);
  220. glVertex3fv(p[20].pt);
  221. if (flat) glTexCoord2fv(p[9].pt);
  222. else glTexCoord2f(1, 0);
  223. glVertex3fv(p[9].pt);
  224. if (flat) glTexCoord2fv(p[17].pt);
  225. else glTexCoord2f(1, 1);
  226. glVertex3fv(p[17].pt);
  227. if (flat) glTexCoord2fv(p[21].pt);
  228. else glTexCoord2f(0, 1);
  229. glVertex3fv(p[21].pt);
  230. glEnd();
  231. }
  232. void Stone::draw_edges(int flat)
  233. {
  234. draw_edges(points, flat);
  235. }
  236. void Stone::draw_edges(Point *p, int flat)
  237. {
  238. Point n1, n2;
  239. glBegin(GL_QUADS);
  240. n1.set(0, 1, 0);
  241. n2.set(1, 0, 0);
  242. draw_edge(n1, n2, p, 10, 1, 0, 11, flat);
  243. n1.set(1, 0, 0);
  244. n2.set(0, -1, 0);
  245. draw_edge(n1, n2, p, 15, 8, 7, 16, flat);
  246. n1.set(1, 0, 0);
  247. n2.set(0, 0, 1);
  248. draw_edge(n1, n2, p, 8, 0, 2, 6, flat);
  249. n1.set(1, 0, 0);
  250. n2.set(0, 0, -1);
  251. draw_edge(n1, n2, p, 11, 15, 17, 9, flat);
  252. n1.set(0, 1, 0);
  253. n2.set(-1, 0, 0);
  254. draw_edge(n1, n2, p, 4, 19, 18, 5, flat);
  255. n1.set(-1, 0, 0);
  256. n2.set(0, -1, 0);
  257. draw_edge(n1, n2, p, 12, 23, 22, 13, flat);
  258. n1.set(-1, 0, 0);
  259. n2.set(0, 0, 1);
  260. draw_edge(n1, n2, p, 5, 12, 14, 3, flat);
  261. n2.set(-1, 0, 0);
  262. n1.set(0, 0, -1);
  263. draw_edge(n1, n2, p, 20, 21, 23, 18, flat);
  264. n1.set(0, 1, 0);
  265. n2.set(0, 0, 1);
  266. draw_edge(n1, n2, p, 1, 4, 3, 2, flat);
  267. n1.set(0, 1, 0);
  268. n2.set(0, 0, -1);
  269. draw_edge(n1, n2, p, 19, 10, 9, 20, flat);
  270. n1.set(0, -1, 0);
  271. n2.set(0, 0, 1);
  272. draw_edge(n1, n2, p, 13, 7, 6, 14, flat);
  273. n1.set(0, -1, 0);
  274. n2.set(0, 0, -1);
  275. draw_edge(n1, n2, p, 16, 22, 21, 17, flat);
  276. glEnd();
  277. }
  278. void Stone::draw_edge(Point n1, Point n2, Point *p,
  279. int a, int b, int c, int d, int flat)
  280. {
  281. glNormal3fv(n1.pt);
  282. if (flat) glTexCoord2fv(p[a].pt);
  283. else glTexCoord2f(0, 0);
  284. glVertex3fv(p[a].pt);
  285. if (flat) glTexCoord2fv(p[b].pt);
  286. else glTexCoord2f(0, 1);
  287. glVertex3fv(p[b].pt);
  288. glNormal3fv(n2.pt);
  289. if (flat) glTexCoord2fv(p[c].pt);
  290. else glTexCoord2f(1, 1);
  291. glVertex3fv(p[c].pt);
  292. if (flat) glTexCoord2fv(p[d].pt);
  293. else glTexCoord2f(1, 0);
  294. glVertex3fv(p[d].pt);
  295. }
  296. void Stone::draw_corners(Point *p, int flat)
  297. {
  298. GLfloat e = 1.0 - erosion;
  299. glBegin(GL_TRIANGLES);
  300. if (flat) glTexCoord2fv(p[0].pt);
  301. else glTexCoord2f(0, 0);
  302. glNormal3f(1, 0, 0);
  303. glVertex3fv(p[0].pt);
  304. if (flat) glTexCoord2fv(p[1].pt);
  305. else glTexCoord2f(1, 0);
  306. glNormal3f(0, 1, 0);
  307. glVertex3fv(p[1].pt);
  308. if (flat) glTexCoord2fv(p[2].pt);
  309. else glTexCoord2f(.5, 1);
  310. glNormal3f(0, 0, 1);
  311. glVertex3fv(p[2].pt);
  312. if (flat) glTexCoord2fv(p[3].pt);
  313. else glTexCoord2f(0, 0);
  314. glNormal3f(0, 0, 1);
  315. glVertex3fv(p[3].pt);
  316. if (flat) glTexCoord2fv(p[4].pt);
  317. else glTexCoord2f(1, 0);
  318. glNormal3f(0, 1, 0);
  319. glVertex3fv(p[4].pt);
  320. if (flat) glTexCoord2fv(p[5].pt);
  321. else glTexCoord2f(.5, 1);
  322. glNormal3f(-1, 0, 0);
  323. glVertex3fv(p[5].pt);
  324. if (flat) glTexCoord2fv(p[6].pt);
  325. else glTexCoord2f(0, 0);
  326. glNormal3f(0, 0, 1);
  327. glVertex3fv(p[6].pt);
  328. if (flat) glTexCoord2fv(p[7].pt);
  329. else glTexCoord2f(1, 0);
  330. glNormal3f(0, -1, 0);
  331. glVertex3fv(p[7].pt);
  332. if (flat) glTexCoord2fv(p[8].pt);
  333. else glTexCoord2f(.5, 1);
  334. glNormal3f(1, 0, 0);
  335. glVertex3fv(p[8].pt);
  336. if (flat) glTexCoord2fv(p[9].pt);
  337. else glTexCoord2f(0, 0);
  338. glNormal3f(0, 0, -1);
  339. glVertex3fv(p[9].pt);
  340. if (flat) glTexCoord2fv(p[10].pt);
  341. else glTexCoord2f(1, 0);
  342. glNormal3f(0, 1, 0);
  343. glVertex3fv(p[10].pt);
  344. if (flat) glTexCoord2fv(p[11].pt);
  345. else glTexCoord2f(.5, 1);
  346. glNormal3f(1, 0, 0);
  347. glVertex3fv(p[11].pt);
  348. if (flat) glTexCoord2fv(p[12].pt);
  349. else glTexCoord2f(0, 0);
  350. glNormal3f(-1, 0, 0);
  351. glVertex3fv(p[12].pt);
  352. if (flat) glTexCoord2fv(p[13].pt);
  353. else glTexCoord2f(1, 0);
  354. glNormal3f(0, -1, 0);
  355. glVertex3fv(p[13].pt);
  356. if (flat) glTexCoord2fv(p[14].pt);
  357. else glTexCoord2f(.5, 1);
  358. glNormal3f(0, 0, 1);
  359. glVertex3fv(p[14].pt);
  360. if (flat) glTexCoord2fv(p[15].pt);
  361. else glTexCoord2f(0, 0);
  362. glNormal3f(1, 0, 0);
  363. glVertex3fv(p[15].pt);
  364. if (flat) glTexCoord2fv(p[16].pt);
  365. else glTexCoord2f(1, 0);
  366. glNormal3f(0, -1, 0);
  367. glVertex3fv(p[16].pt);
  368. if (flat) glTexCoord2fv(p[17].pt);
  369. else glTexCoord2f(.5, 1);
  370. glNormal3f(0, 0, -1);
  371. glVertex3fv(p[17].pt);
  372. if (flat) glTexCoord2fv(p[18].pt);
  373. else glTexCoord2f(0, 0);
  374. glNormal3f(-1, 0, 0);
  375. glVertex3fv(p[18].pt);
  376. if (flat) glTexCoord2fv(p[19].pt);
  377. else glTexCoord2f(1, 0);
  378. glNormal3f(0, 1, 0);
  379. glVertex3fv(p[19].pt);
  380. if (flat) glTexCoord2fv(p[20].pt);
  381. else glTexCoord2f(.5, 1);
  382. glNormal3f(0, 0, -1);
  383. glVertex3fv(p[20].pt);
  384. if (flat) glTexCoord2fv(p[21].pt);
  385. else glTexCoord2f(0, 0);
  386. glNormal3f(0, 0, -1);
  387. glVertex3fv(p[21].pt);
  388. if (flat) glTexCoord2fv(p[22].pt);
  389. else glTexCoord2f(1, 0);
  390. glNormal3f(0, -1, 0);
  391. glVertex3fv(p[22].pt);
  392. if (flat) glTexCoord2fv(p[23].pt);
  393. else glTexCoord2f(.5, 1);
  394. glNormal3f(-1, 0, 0);
  395. glVertex3fv(p[23].pt);
  396. glEnd();
  397. }
  398. void Stone::draw_shadow(Point dlight)
  399. {
  400. Point p[24];
  401. int i;
  402. transform_points();
  403. for (i = 0; i < 24; i++) {
  404. p[i] = points[i];
  405. if (p[i].pt[2] < 0.0) p[i].pt[2] = 0.0;
  406. p[i] = p[i].project_direction(dlight);
  407. }
  408. draw_faces(p, 1);
  409. draw_edges(p, 1);
  410. draw_corners(p, 1);
  411. }
  412. void Stone::draw_shadow(Point dlight, GLfloat blur,
  413. Color color, Color diffuse)
  414. {
  415. float b = 1.0 + blur;
  416. float c, s;
  417. Point p[8], pp[8];
  418. Point d, n;
  419. Color colorp, diffusep;
  420. int draw[6];
  421. int i;
  422. if (blur == 0.0) {
  423. draw_shadow(dlight);
  424. return;
  425. }
  426. colorp = color;
  427. color.c[3] = 1;
  428. colorp.c[3] = 0;
  429. diffusep = diffuse;
  430. diffuse.c[3] = 1;
  431. diffusep.c[3] = 0;
  432. /* We're being slightly cowardly here and ignoring the erosion - it
  433. * shouldn't make a big difference */
  434. p[0].set(-1, -1, -1);
  435. pp[0] = p[0];
  436. p[1].set(1, -1, -1);
  437. pp[1] = p[1];
  438. p[2].set(1, 1, -1);
  439. pp[2] = p[2];
  440. p[3].set(-1, 1, -1);
  441. pp[3] = p[3];
  442. p[4].set(-1, -1, 1);
  443. pp[4] = p[4];
  444. p[5].set(1, -1, 1);
  445. pp[5] = p[5];
  446. p[6].set(1, 1, 1);
  447. pp[6] = p[6];
  448. p[7].set(-1, 1, 1);
  449. pp[7] = p[7];
  450. c = cos(radians(rotation));
  451. s = sin(radians(rotation));
  452. for (i = 0; i < 8; i++) {
  453. p[i] = transform_point(p[i], c, s);
  454. /* This is a complete and utter hack - the net effect is that
  455. * points which are higher are displaced further when the penumbra
  456. * is drawn */
  457. d = dimensions;
  458. d.pt[0] += blur * (pp[i].pt[2] + translation.pt[2]);
  459. d.pt[1] += blur * (pp[i].pt[2] + translation.pt[2]);
  460. d.pt[2] += blur * (pp[i].pt[2] + translation.pt[2]);
  461. pp[i] = pp[i].scale(d);
  462. pp[i] = trans_rot_point(pp[i], c, s);
  463. if (p[i].pt[2] < 0.0) p[i].pt[2] = 0.0;
  464. p[i] = p[i].project_direction(dlight);
  465. if (pp[i].pt[2] < 0.0) pp[i].pt[2] = 0.0;
  466. pp[i] = pp[i].project_direction(dlight);
  467. }
  468. /* Compute whether or not we should draw various parts of the shadow
  469. * based upon the normal direction */
  470. if (dlight.pt[2] > 0.0) dlight *= -1.0;
  471. n.set(0, 0, -1);
  472. n = n.rotate_aboutz(c, s);
  473. draw[0] = (dlight.dot(n) < 0.0);
  474. n.set(0, -1, 0);
  475. n = n.rotate_aboutz(c, s);
  476. draw[1] = (dlight.dot(n) < 0.0);
  477. n.set(1, 0, 0);
  478. n = n.rotate_aboutz(c, s);
  479. draw[2] = (dlight.dot(n) < 0.0);
  480. n.set(0, 1, 0);
  481. n = n.rotate_aboutz(c, s);
  482. draw[3] = (dlight.dot(n) < 0.0);
  483. n.set(-1, 0, 0);
  484. n = n.rotate_aboutz(c, s);
  485. draw[4] = (dlight.dot(n) < 0.0);
  486. n.set(0, 0, 1);
  487. n = n.rotate_aboutz(c, s);
  488. draw[5] = (dlight.dot(n) < 0.0);
  489. /* This part draws the "real" shadow */
  490. glColor4fv(color.c);
  491. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse.c);
  492. glBegin(GL_QUADS);
  493. if (draw[0]) {
  494. glVertex2fv(p[0].pt);
  495. glVertex2fv(p[1].pt);
  496. glVertex2fv(p[2].pt);
  497. glVertex2fv(p[3].pt);
  498. }
  499. if (draw[1]) {
  500. glVertex2fv(p[0].pt);
  501. glVertex2fv(p[1].pt);
  502. glVertex2fv(p[5].pt);
  503. glVertex2fv(p[4].pt);
  504. }
  505. if (draw[2]) {
  506. glVertex2fv(p[1].pt);
  507. glVertex2fv(p[2].pt);
  508. glVertex2fv(p[6].pt);
  509. glVertex2fv(p[5].pt);
  510. }
  511. if (draw[3]) {
  512. glVertex2fv(p[2].pt);
  513. glVertex2fv(p[3].pt);
  514. glVertex2fv(p[7].pt);
  515. glVertex2fv(p[6].pt);
  516. }
  517. if (draw[4]) {
  518. glVertex2fv(p[3].pt);
  519. glVertex2fv(p[0].pt);
  520. glVertex2fv(p[4].pt);
  521. glVertex2fv(p[7].pt);
  522. }
  523. if (draw[5]) {
  524. glVertex2fv(p[4].pt);
  525. glVertex2fv(p[5].pt);
  526. glVertex2fv(p[6].pt);
  527. glVertex2fv(p[7].pt);
  528. }
  529. glEnd();
  530. /* This part draws the penumbra */
  531. glEnable(GL_BLEND);
  532. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  533. glBegin(GL_QUADS);
  534. /* Top */
  535. if (draw[5]) {
  536. if (!draw[4]) {
  537. glColor4fv(color.c);
  538. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse.c);
  539. glVertex2fv(p[4].pt);
  540. glVertex2fv(p[5].pt);
  541. glColor4fv(colorp.c);
  542. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffusep.c);
  543. glVertex2fv(pp[5].pt);
  544. glVertex2fv(pp[4].pt);
  545. }
  546. if (!draw[2]) {
  547. glColor4fv(color.c);
  548. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse.c);
  549. glVertex2fv(p[5].pt);
  550. glVertex2fv(p[6].pt);
  551. glColor4fv(colorp.c);
  552. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffusep.c);
  553. glVertex2fv(pp[6].pt);
  554. glVertex2fv(pp[5].pt);
  555. }
  556. if (!draw[3]) {
  557. glColor4fv(color.c);
  558. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse.c);
  559. glVertex2fv(p[6].pt);
  560. glVertex2fv(p[7].pt);
  561. glColor4fv(colorp.c);
  562. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffusep.c);
  563. glVertex2fv(pp[7].pt);
  564. glVertex2fv(pp[6].pt);
  565. }
  566. if (!draw[4]) {
  567. glColor4fv(color.c);
  568. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse.c);
  569. glVertex2fv(p[7].pt);
  570. glVertex2fv(p[4].pt);
  571. glColor4fv(colorp.c);
  572. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffusep.c);
  573. glVertex2fv(pp[4].pt);
  574. glVertex2fv(pp[7].pt);
  575. }
  576. }
  577. /* End of Top */
  578. /* Sides */
  579. if ((draw[1] || draw[4]) && !(draw[1] && draw[4])) {
  580. glColor4fv(color.c);
  581. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse.c);
  582. glVertex2fv(p[0].pt);
  583. glVertex2fv(p[4].pt);
  584. glColor4fv(colorp.c);
  585. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffusep.c);
  586. glVertex2fv(pp[4].pt);
  587. glVertex2fv(pp[0].pt);
  588. }
  589. if ((draw[1] || draw[2]) && !(draw[1] && draw[2])) {
  590. glColor4fv(color.c);
  591. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse.c);
  592. glVertex2fv(p[1].pt);
  593. glVertex2fv(p[5].pt);
  594. glColor4fv(colorp.c);
  595. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffusep.c);
  596. glVertex2fv(pp[5].pt);
  597. glVertex2fv(pp[1].pt);
  598. }
  599. if ((draw[3] || draw[2]) && !(draw[3] && draw[2])) {
  600. glColor4fv(color.c);
  601. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse.c);
  602. glVertex2fv(p[2].pt);
  603. glVertex2fv(p[6].pt);
  604. glColor4fv(colorp.c);
  605. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffusep.c);
  606. glVertex2fv(pp[6].pt);
  607. glVertex2fv(pp[2].pt);
  608. }
  609. if ((draw[3] || draw[4]) && !(draw[3] && draw[4])) {
  610. glColor4fv(color.c);
  611. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse.c);
  612. glVertex2fv(p[3].pt);
  613. glVertex2fv(p[7].pt);
  614. glColor4fv(colorp.c);
  615. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffusep.c);
  616. glVertex2fv(pp[7].pt);
  617. glVertex2fv(pp[3].pt);
  618. }
  619. /* End of Sides */
  620. /* Bottom */
  621. if (draw[0]) {
  622. if (!draw[1]) {
  623. glColor4fv(color.c);
  624. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse.c);
  625. glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, diffuse.c);
  626. glVertex2fv(p[0].pt);
  627. glVertex2fv(p[1].pt);
  628. glColor4fv(colorp.c);
  629. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffusep.c);
  630. glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, diffusep.c);
  631. glVertex2fv(pp[1].pt);
  632. glVertex2fv(pp[0].pt);
  633. }
  634. if (!draw[2]) {
  635. glColor4fv(color.c);
  636. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse.c);
  637. glVertex2fv(p[1].pt);
  638. glVertex2fv(p[2].pt);
  639. glColor4fv(colorp.c);
  640. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffusep.c);
  641. glVertex2fv(pp[2].pt);
  642. glVertex2fv(pp[1].pt);
  643. }
  644. if (!draw[3]) {
  645. glColor4fv(color.c);
  646. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse.c);
  647. glVertex2fv(p[2].pt);
  648. glVertex2fv(p[3].pt);
  649. glColor4fv(colorp.c);
  650. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffusep.c);
  651. glVertex2fv(pp[3].pt);
  652. glVertex2fv(pp[2].pt);
  653. }
  654. if (!draw[4]) {
  655. glColor4fv(color.c);
  656. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse.c);
  657. glVertex2fv(p[3].pt);
  658. glVertex2fv(p[0].pt);
  659. glColor4fv(colorp.c);
  660. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffusep.c);
  661. glVertex2fv(pp[0].pt);
  662. glVertex2fv(pp[3].pt);
  663. }
  664. }
  665. /* End of Bottom */
  666. glEnd();
  667. glDisable(GL_BLEND);
  668. }