gsd_wire.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  1. /*!
  2. \file gsd_wire.c
  3. \brief OGSF library -
  4. GRASS OpenGL gsurf OGSF Library
  5. (C) 1999-2008 by the GRASS Development Team
  6. This program is free software under the
  7. GNU General Public License (>=v2).
  8. Read the file COPYING that comes with GRASS
  9. for details.
  10. \author Bill Brown USACERL (January 1993)
  11. */
  12. #include <stdio.h>
  13. #include <grass/gstypes.h>
  14. #include "gsget.h"
  15. #include "rowcol.h"
  16. /*
  17. #define TRACE_DFUNCS
  18. */
  19. #define DO_ARROWS
  20. /************************************************************************/
  21. /* Notes on exageration:
  22. vertical exageration is of two forms:
  23. 1) global exageration (from geoview struct)
  24. 2) vertical exageration for each surface - not implemented
  25. */
  26. /************************************************************************/
  27. /* may need to add more parameters to tell it which window or off_screen
  28. * pixmap to draw into. nah - just have one current (OpenGL limitation)
  29. */
  30. int gsd_wire_surf(geosurf * surf)
  31. {
  32. int desc, ret;
  33. #ifdef TRACE_DFUNCS
  34. {
  35. Gs_status("gsd_wire_surf");
  36. }
  37. #endif
  38. desc = ATT_TOPO;
  39. switch (gs_get_att_src(surf, desc)) {
  40. case NOTSET_ATT:
  41. ret = (-1);
  42. break;
  43. case MAP_ATT:
  44. if (surf->draw_mode & DM_GRID_WIRE)
  45. ret = (gsd_wire_surf_map(surf)); /* draw mesh */
  46. else
  47. ret = (gsd_coarse_surf_map(surf)); /* draw coarse surf */
  48. #ifdef DO_ARROWS
  49. /*
  50. gsd_wire_arrows(surf);
  51. */
  52. #endif
  53. break;
  54. case CONST_ATT:
  55. ret = (gsd_wire_surf_const(surf, surf->att[desc].constant));
  56. break;
  57. case FUNC_ATT:
  58. ret = (gsd_wire_surf_func(surf, surf->att[desc].user_func));
  59. break;
  60. default:
  61. ret = (-1);
  62. break;
  63. }
  64. return (ret);
  65. }
  66. /************************************************************************/
  67. int gsd_wire_surf_map(geosurf * surf)
  68. {
  69. int check_mask, check_color;
  70. typbuff *buff, *cobuff;
  71. int xmod, ymod, row, col, cnt, xcnt, ycnt, x1off;
  72. long offset, y1off;
  73. float pt[4], xres, yres, ymax, zexag;
  74. int col_src, curcolor;
  75. gsurf_att *coloratt;
  76. #ifdef TRACE_DFUNCS
  77. {
  78. Gs_status("gsd_wire_surf_map");
  79. }
  80. #endif
  81. buff = gs_get_att_typbuff(surf, ATT_TOPO, 0);
  82. cobuff = gs_get_att_typbuff(surf, ATT_COLOR, 0);
  83. gs_update_curmask(surf);
  84. check_mask = surf->curmask ? 1 : 0;
  85. /*
  86. checks ATT_TOPO & ATT_COLOR no_zero flags, make a mask from each,
  87. combine it/them with any current mask, put in typbuff:
  88. if(surf->att[ATT_TOPO].constant)
  89. */
  90. xmod = surf->x_modw;
  91. ymod = surf->y_modw;
  92. xres = xmod * surf->xres;
  93. yres = ymod * surf->yres;
  94. ymax = (surf->rows - 1) * surf->yres;
  95. xcnt = 1 + (surf->cols - 1) / xmod;
  96. ycnt = 1 + (surf->rows - 1) / ymod;
  97. gsd_pushmatrix();
  98. gsd_do_scale(1);
  99. gsd_translate(surf->x_trans, surf->y_trans, surf->z_trans);
  100. zexag = surf->z_exag;
  101. gsd_colormode(CM_COLOR);
  102. /* will need to check for color source of FUNC_ATT & NOTSET_ATT,
  103. or else use more general and inefficient gets */
  104. check_color = (surf->wire_color == WC_COLOR_ATT);
  105. if (check_color) {
  106. coloratt = &(surf->att[ATT_COLOR]);
  107. col_src = surf->att[ATT_COLOR].att_src;
  108. if (col_src != MAP_ATT) {
  109. if (col_src == CONST_ATT) {
  110. gsd_color_func((int) surf->att[ATT_COLOR].constant);
  111. }
  112. else {
  113. gsd_color_func(surf->wire_color);
  114. }
  115. check_color = 0;
  116. }
  117. }
  118. else {
  119. gsd_color_func(surf->wire_color);
  120. }
  121. /* would also be good to check if colormap == surfmap, to increase speed */
  122. for (row = 0; row < ycnt; row++) {
  123. pt[Y] = ymax - row * yres;
  124. y1off = row * ymod * surf->cols;
  125. gsd_bgnline();
  126. cnt = 0;
  127. for (col = 0; col < xcnt; col++) {
  128. pt[X] = col * xres;
  129. x1off = col * xmod;
  130. offset = x1off + y1off;
  131. if (check_mask) {
  132. if (BM_get(surf->curmask, col * xmod, row * ymod)) {
  133. gsd_endline();
  134. gsd_bgnline();
  135. cnt = 0;
  136. continue;
  137. }
  138. }
  139. GET_MAPATT(buff, offset, pt[Z]);
  140. if (check_color) {
  141. curcolor = gs_mapcolor(cobuff, coloratt, offset);
  142. gsd_color_func(curcolor);
  143. /* could use this & skip the GET if colordata == elevdata
  144. gsd_color_func(gs_fastmapcolor(cobuff, coloratt, offset,
  145. (int)pt[Z]));
  146. */
  147. }
  148. pt[Z] = pt[Z] * zexag;
  149. gsd_vert_func(pt);
  150. if (cnt == 255) {
  151. gsd_endline();
  152. gsd_bgnline();
  153. cnt = 0;
  154. gsd_vert_func(pt);
  155. }
  156. cnt++;
  157. }
  158. gsd_endline();
  159. }
  160. for (col = 0; col < xcnt; col++) {
  161. pt[X] = col * xres;
  162. x1off = col * xmod;
  163. gsd_bgnline();
  164. cnt = 0;
  165. for (row = 0; row < ycnt; row++) {
  166. pt[Y] = ymax - row * yres;
  167. y1off = row * ymod * surf->cols;
  168. offset = x1off + y1off;
  169. if (check_mask) {
  170. if (BM_get(surf->curmask, col * xmod, row * ymod)) {
  171. gsd_endline();
  172. gsd_bgnline();
  173. cnt = 0;
  174. continue;
  175. }
  176. }
  177. GET_MAPATT(buff, offset, pt[Z]);
  178. if (check_color) {
  179. curcolor = gs_mapcolor(cobuff, coloratt, offset);
  180. gsd_color_func(curcolor);
  181. /* could use this & skip the GET if colordata == elevdata
  182. gsd_color_func(gs_fastmapcolor(coloratt, offset, (int)pt[Z]));
  183. */
  184. }
  185. pt[Z] = pt[Z] * zexag;
  186. gsd_vert_func(pt);
  187. if (cnt == 255) {
  188. gsd_endline();
  189. gsd_bgnline();
  190. cnt = 0;
  191. gsd_vert_func(pt);
  192. }
  193. cnt++;
  194. }
  195. gsd_endline();
  196. }
  197. gsd_popmatrix();
  198. gsd_colormode(CM_DIFFUSE);
  199. return (1);
  200. }
  201. /************************************************************************/
  202. int gsd_wire_surf_const(geosurf * surf, float k)
  203. {
  204. int do_diff, check_mask, check_color;
  205. int xmod, ymod, row, col, cnt, xcnt, ycnt, x1off;
  206. long offset, y1off;
  207. float pt[4], xres, yres, ymax, zexag;
  208. int col_src;
  209. gsurf_att *coloratt;
  210. typbuff *cobuff;
  211. #ifdef TRACE_DFUNCS
  212. {
  213. Gs_status("gsd_wire_surf_const");
  214. }
  215. #endif
  216. cobuff = gs_get_att_typbuff(surf, ATT_COLOR, 0);
  217. gs_update_curmask(surf);
  218. check_mask = surf->curmask ? 1 : 0;
  219. do_diff = (NULL != gsdiff_get_SDref());
  220. xmod = surf->x_modw;
  221. ymod = surf->y_modw;
  222. xres = xmod * surf->xres;
  223. yres = ymod * surf->yres;
  224. xcnt = 1 + (surf->cols - 1) / xmod;
  225. ycnt = 1 + (surf->rows - 1) / ymod;
  226. ymax = (surf->rows - 1) * surf->yres;
  227. gsd_pushmatrix();
  228. gsd_do_scale(1);
  229. gsd_translate(surf->x_trans, surf->y_trans, surf->z_trans);
  230. zexag = surf->z_exag;
  231. gsd_colormode(CM_COLOR);
  232. /* will need to check for color source of FUNC_ATT & NOTSET_ATT,
  233. or else use more general and inefficient gets */
  234. check_color = (surf->wire_color == WC_COLOR_ATT);
  235. if (check_color) {
  236. coloratt = &(surf->att[ATT_COLOR]);
  237. col_src = surf->att[ATT_COLOR].att_src;
  238. if (col_src != MAP_ATT) {
  239. if (col_src == CONST_ATT) {
  240. gsd_color_func((int) surf->att[ATT_COLOR].constant);
  241. }
  242. else {
  243. gsd_color_func(surf->wire_color);
  244. }
  245. check_color = 0;
  246. }
  247. }
  248. else {
  249. gsd_color_func(surf->wire_color);
  250. }
  251. pt[Z] = k * zexag;
  252. for (row = 0; row < ycnt; row++) {
  253. pt[Y] = ymax - row * yres;
  254. y1off = row * ymod * surf->cols;
  255. gsd_bgnline();
  256. cnt = 0;
  257. for (col = 0; col < xcnt; col++) {
  258. pt[X] = col * xres;
  259. x1off = col * xmod;
  260. offset = x1off + y1off;
  261. if (check_mask) {
  262. if (BM_get(surf->curmask, col * xmod, row * ymod)) {
  263. gsd_endline();
  264. gsd_bgnline();
  265. cnt = 0;
  266. continue;
  267. }
  268. }
  269. if (check_color) {
  270. gsd_color_func(gs_mapcolor(cobuff, coloratt, offset));
  271. }
  272. if (do_diff) {
  273. pt[Z] = gsdiff_do_SD(k * zexag, offset);
  274. }
  275. gsd_vert_func(pt);
  276. if (cnt == 255) {
  277. gsd_endline();
  278. gsd_bgnline();
  279. cnt = 0;
  280. gsd_vert_func(pt);
  281. }
  282. cnt++;
  283. }
  284. gsd_endline();
  285. }
  286. for (col = 0; col < xcnt; col++) {
  287. pt[X] = col * xres;
  288. x1off = col * xmod;
  289. gsd_bgnline();
  290. cnt = 0;
  291. for (row = 0; row < ycnt; row++) {
  292. pt[Y] = ymax - row * yres;
  293. y1off = row * ymod * surf->cols;
  294. offset = x1off + y1off;
  295. if (check_mask) {
  296. if (BM_get(surf->curmask, col * xmod, row * ymod)) {
  297. gsd_endline();
  298. gsd_bgnline();
  299. cnt = 0;
  300. continue;
  301. }
  302. }
  303. if (check_color) {
  304. gsd_color_func(gs_mapcolor(cobuff, coloratt, offset));
  305. }
  306. if (do_diff) {
  307. pt[Z] = gsdiff_do_SD(k * zexag, offset);
  308. }
  309. gsd_vert_func(pt);
  310. if (cnt == 255) {
  311. gsd_endline();
  312. gsd_bgnline();
  313. cnt = 0;
  314. gsd_vert_func(pt);
  315. }
  316. cnt++;
  317. }
  318. gsd_endline();
  319. }
  320. gsd_popmatrix();
  321. gsd_colormode(CM_DIFFUSE);
  322. return (1);
  323. }
  324. /************************************************************************/
  325. int gsd_wire_surf_func(geosurf * gs, int (*user_func) ())
  326. {
  327. return (1);
  328. }
  329. /************************************************************************/
  330. /* need to do Zexag scale of normal for arrow direction, drawing
  331. routine unexags z for arrow */
  332. int gsd_wire_arrows(geosurf * surf)
  333. {
  334. typbuff *buff, *cobuff;
  335. int check_mask, check_color;
  336. int xmod, ymod, row, col, xcnt, ycnt;
  337. long offset, y1off;
  338. float tx, ty, tz, sz;
  339. float n[3], pt[4], xres, yres, ymax, zexag;
  340. int col_src, curcolor;
  341. gsurf_att *coloratt;
  342. #ifdef TRACE_DFUNCS
  343. {
  344. Gs_status("gsd_norm_arrows");
  345. }
  346. #endif
  347. /* avoid scaling by zero */
  348. GS_get_scale(&tx, &ty, &tz, 1);
  349. if (tz == 0.0) {
  350. return (0);
  351. }
  352. sz = GS_global_exag();
  353. gs_update_curmask(surf);
  354. check_mask = surf->curmask ? 1 : 0;
  355. /*
  356. checks ATT_TOPO & ATT_COLOR no_zero flags, make a mask from each,
  357. combine it/them with any current mask, put in surf->curmask:
  358. */
  359. check_color = 1;
  360. coloratt = &(surf->att[ATT_COLOR]);
  361. col_src = surf->att[ATT_COLOR].att_src;
  362. if (col_src != MAP_ATT) {
  363. if (col_src == CONST_ATT) {
  364. curcolor = (int) surf->att[ATT_COLOR].constant;
  365. }
  366. else {
  367. curcolor = surf->wire_color;
  368. }
  369. check_color = 0;
  370. }
  371. buff = gs_get_att_typbuff(surf, ATT_TOPO, 0);
  372. cobuff = gs_get_att_typbuff(surf, ATT_COLOR, 0);
  373. xmod = surf->x_modw;
  374. ymod = surf->y_modw;
  375. xres = xmod * surf->xres;
  376. yres = ymod * surf->yres;
  377. ymax = (surf->rows - 1) * surf->yres;
  378. xcnt = 1 + (surf->cols - 1) / xmod;
  379. ycnt = 1 + (surf->rows - 1) / ymod;
  380. gsd_pushmatrix();
  381. gsd_do_scale(1);
  382. gsd_translate(surf->x_trans, surf->y_trans, surf->z_trans);
  383. zexag = surf->z_exag;
  384. /* CURRENTLY ALWAYS 1.0 */
  385. gsd_colormode(CM_COLOR);
  386. for (row = 0; row < ycnt; row++) {
  387. pt[Y] = ymax - row * yres;
  388. y1off = row * ymod * surf->cols;
  389. for (col = 0; col < xcnt; col++) {
  390. pt[X] = col * xres;
  391. offset = col * xmod + y1off;
  392. if (check_mask) {
  393. if (BM_get(surf->curmask, col * xmod, row * ymod)) {
  394. continue;
  395. }
  396. }
  397. FNORM(surf->norms[offset], n);
  398. GET_MAPATT(buff, offset, pt[Z]);
  399. pt[Z] *= zexag;
  400. if (check_color) {
  401. curcolor = gs_mapcolor(cobuff, coloratt, offset);
  402. }
  403. gsd_arrow(pt, curcolor, xres * 2, n, sz, surf);
  404. } /* ea col */
  405. } /* ea row */
  406. gsd_popmatrix();
  407. gsd_colormode(CM_DIFFUSE);
  408. return (1);
  409. }
  410. /***********************************************************
  411. * New (TEST) wire routine that draws low res surface
  412. * Based on new Trinagle Fan routine
  413. * Resolution is a function of current surface resolution
  414. * times wire resolution
  415. * TODO - normals have to be recalculated before proper low
  416. * res surface can be drawn
  417. * In window optimization has been removed
  418. *************************************************************/
  419. int gsd_coarse_surf_map(geosurf * surf)
  420. {
  421. int check_mask, check_color, check_transp;
  422. int check_material, check_emis, check_shin;
  423. typbuff *buff, *cobuff, *trbuff, *embuff, *shbuff;
  424. int xmod, ymod;
  425. int row, col, xcnt, ycnt;
  426. long y1off, y2off, y3off;
  427. long offset2[10];
  428. float pt2[10][2];
  429. int ii;
  430. float x1, x2, x3, y1, y2, y3, tx, ty, tz, ttr;
  431. float n[3], pt[4], xres, yres, ymax, zexag;
  432. int em_src, sh_src, trans_src, col_src, curcolor;
  433. gsurf_att *ematt, *shatt, *tratt, *coloratt;
  434. int datarow1, datacol1, datarow2, datacol2, datarow3, datacol3;
  435. float kem, ksh, pkem, pksh;
  436. unsigned int ktrans;
  437. int step_val = 2 * surf->x_modw; /* should always be factor of 2 for fan */
  438. int start_val = surf->x_modw;
  439. /* ensure normals are correct */
  440. gs_calc_normals(surf);
  441. /* avoid scaling by zero */
  442. GS_get_scale(&tx, &ty, &tz, 1);
  443. if (tz == 0.0) {
  444. return (gsd_surf_const(surf, 0.0));
  445. }
  446. /* else if (surf->z_exag == 0.0)
  447. {
  448. return(gsd_surf_const(surf, surf->z_min));
  449. }
  450. NOT YET IMPLEMENTED */
  451. buff = gs_get_att_typbuff(surf, ATT_TOPO, 0);
  452. cobuff = gs_get_att_typbuff(surf, ATT_COLOR, 0);
  453. gs_update_curmask(surf);
  454. check_mask = surf->curmask ? 1 : 0;
  455. /*
  456. checks ATT_TOPO & ATT_COLOR no_zero flags, make a mask from each,
  457. combine it/them with any current mask, put in surf->curmask:
  458. */
  459. xmod = surf->x_mod;
  460. ymod = surf->y_mod;
  461. xres = xmod * surf->xres;
  462. yres = ymod * surf->yres;
  463. ymax = (surf->rows - 1) * surf->yres;
  464. xcnt = VCOLS(surf);
  465. ycnt = VROWS(surf);
  466. gsd_pushmatrix();
  467. gsd_do_scale(1);
  468. gsd_translate(surf->x_trans, surf->y_trans, surf->z_trans);
  469. zexag = surf->z_exag;
  470. gsd_colormode(CM_DIFFUSE);
  471. /* CURRENTLY ALWAYS 1.0 */
  472. #ifdef CALC_AREA
  473. sz = GS_global_exag();
  474. #endif
  475. /* TODO: get rid of (define) these magic numbers scaling the attribute vals */
  476. check_transp = 0;
  477. tratt = &(surf->att[ATT_TRANSP]);
  478. ktrans = (255 << 24);
  479. trans_src = surf->att[ATT_TRANSP].att_src;
  480. if (CONST_ATT == trans_src && surf->att[ATT_TRANSP].constant != 0.0) {
  481. ktrans = (255 - (int) surf->att[ATT_TRANSP].constant) << 24;
  482. gsd_blend(1);
  483. gsd_zwritemask(0x0);
  484. }
  485. else if (MAP_ATT == trans_src) {
  486. trbuff = gs_get_att_typbuff(surf, ATT_TRANSP, 0);
  487. check_transp = trbuff ? 1 : 0;
  488. gsd_blend(1);
  489. gsd_zwritemask(0x0);
  490. }
  491. check_emis = 0;
  492. ematt = &(surf->att[ATT_EMIT]);
  493. kem = 0.0;
  494. pkem = 1.0;
  495. em_src = surf->att[ATT_EMIT].att_src;
  496. if (CONST_ATT == em_src) {
  497. kem = surf->att[ATT_EMIT].constant / 255.;
  498. }
  499. else if (MAP_ATT == em_src) {
  500. embuff = gs_get_att_typbuff(surf, ATT_EMIT, 0);
  501. check_emis = embuff ? 1 : 0;
  502. }
  503. check_shin = 0;
  504. shatt = &(surf->att[ATT_SHINE]);
  505. ksh = 0.0;
  506. pksh = 1.0;
  507. sh_src = surf->att[ATT_SHINE].att_src;
  508. if (CONST_ATT == sh_src) {
  509. ksh = surf->att[ATT_SHINE].constant / 255.;
  510. gsd_set_material(1, 0, ksh, kem, 0x0);
  511. }
  512. else if (MAP_ATT == sh_src) {
  513. shbuff = gs_get_att_typbuff(surf, ATT_SHINE, 0);
  514. check_shin = shbuff ? 1 : 0;
  515. }
  516. /* will need to check for color source of FUNC_ATT & NOTSET_ATT,
  517. or else use more general and inefficient gets */
  518. check_color = 1;
  519. coloratt = &(surf->att[ATT_COLOR]);
  520. col_src = surf->att[ATT_COLOR].att_src;
  521. if (col_src != MAP_ATT) {
  522. if (col_src == CONST_ATT) {
  523. curcolor = (int) surf->att[ATT_COLOR].constant;
  524. }
  525. else {
  526. curcolor = surf->wire_color;
  527. }
  528. check_color = 0;
  529. }
  530. check_material = (check_shin || check_emis || (kem && check_color));
  531. /* would also be good to check if colormap == surfmap, to increase speed */
  532. /* will also need to set check_transp, check_shine, etc & fix material */
  533. for (row = start_val; row <= ycnt-start_val; row+=step_val) {
  534. datarow1 = row * ymod;
  535. datarow2 = (row - (step_val/2)) * ymod;
  536. datarow3 = (row + (step_val/2)) * ymod;
  537. y1 = ymax - row*yres;
  538. y2 = ymax - (row-(step_val/2))*yres;
  539. y3 = ymax - (row+(step_val/2))*yres;
  540. y1off = row * ymod * surf->cols;
  541. y2off = (row - (step_val/2)) * ymod * surf->cols;
  542. y3off = (row + (step_val/2)) * ymod * surf->cols;
  543. for (col = start_val; col <= xcnt-start_val; col+=step_val) {
  544. datacol1 = col * xmod;
  545. datacol2 = (col - (step_val/2)) * xmod;
  546. datacol3 = (col + (step_val/2)) * xmod;
  547. x1 = col*xres;
  548. x2 = (col-(step_val/2))*xres;
  549. x3 = (col+(step_val/2))*xres;
  550. /* Do not need BM_get because GET_MAPATT calls
  551. * same and returns zero if masked
  552. */
  553. offset2[0] = y1off+datacol1; /* fan center */
  554. pt2[0][X] = x1; pt2[0][Y] = y1; /* fan center */
  555. pt[X]=pt2[0][X]; pt[Y] = pt2[0][Y];
  556. if ( !GET_MAPATT(buff, offset2[0], pt[Z]) )
  557. continue; /* masked */
  558. pt[Z] *= zexag;
  559. offset2[1] = y2off+datacol2;
  560. offset2[2] = y2off+datacol1;
  561. offset2[3] = y2off+datacol3;
  562. offset2[4] = y1off+datacol3;
  563. offset2[5] = y3off+datacol3;
  564. offset2[6] = y3off+datacol1;
  565. offset2[7] = y3off+datacol2;
  566. offset2[8] = y1off+datacol2;
  567. offset2[9] = y2off+datacol2; /* repeat 1st corner to close */
  568. pt2[1][X] = x2; pt2[1][Y] = y2;
  569. pt2[2][X] = x1; pt2[2][Y] = y2;
  570. pt2[3][X] = x3; pt2[3][Y] = y2;
  571. pt2[4][X] = x3; pt2[4][Y] = y1;
  572. pt2[5][X] = x3; pt2[5][Y] = y3;
  573. pt2[6][X] = x1; pt2[6][Y] = y3;
  574. pt2[7][X] = x2; pt2[7][Y] = y3;
  575. pt2[8][X] = x2; pt2[8][Y] = y1;
  576. pt2[9][X] = x2; pt2[9][Y] = y2; /* repeat 1st corner to close */
  577. /* Run through triangle fan */
  578. gsd_bgntfan();
  579. for (ii = 0; ii < 10; ii++) {
  580. if ( ii > 0) {
  581. pt[X]=pt2[ii][X]; pt[Y] = pt2[ii][Y];
  582. if ( !GET_MAPATT(buff, offset2[ii], pt[Z]) )
  583. continue;
  584. pt[Z] *= zexag;
  585. }
  586. FNORM(surf->norms[offset2[ii]], n);
  587. if (check_color)
  588. curcolor = gs_mapcolor(cobuff, coloratt, offset2[ii]);
  589. if (check_transp) {
  590. GET_MAPATT(trbuff, offset2[ii], ttr);
  591. ktrans = (char) SCALE_ATT(tratt, ttr, 0, 255);
  592. ktrans = (char) (255 - ktrans) << 24;
  593. }
  594. if (check_material) {
  595. if (check_emis) {
  596. GET_MAPATT(embuff, offset2[ii], kem);
  597. kem = SCALE_ATT(ematt, kem, 0., 1.);
  598. }
  599. if (check_shin) {
  600. GET_MAPATT(shbuff, offset2[ii], ksh);
  601. ksh = SCALE_ATT(shatt, ksh, 0., 1.);
  602. }
  603. if (pksh != ksh || pkem != kem
  604. || (kem && check_color)) {
  605. pksh = ksh;
  606. pkem = kem;
  607. gsd_set_material(check_shin, check_emis,
  608. ksh, kem, curcolor);
  609. }
  610. }
  611. gsd_litvert_func(n, ktrans | curcolor, pt);
  612. } /* close ii loop */
  613. gsd_endtfan();
  614. } /* end col */
  615. } /* end row */
  616. gsd_popmatrix();
  617. /*
  618. gsd_colormode(CM_DIFFUSE);
  619. */
  620. gsd_blend(0);
  621. gsd_zwritemask(0xffffffff);
  622. return (0);
  623. }