Objekt_editor_render.cpp 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269
  1. /*
  2. Renderovaci rutiny
  3. */
  4. #include "mss_on.h"
  5. #include <windows.h>
  6. #include <stdio.h>
  7. #include <math.h>
  8. #include <direct.h>
  9. #include <float.h>
  10. #include <assert.h>
  11. #include "objekt_editor_all.h"
  12. #include "dbgwnd.h"
  13. #define RIF(min,max) (((max)+(min))*0.5f)
  14. #define DIF(min,max) (((max)-(min))*0.5f)
  15. void oe_kresli_kameru(KAMERA * p_cam, int pyr)
  16. {
  17. kresli_caru(&p_cam->p, &p_cam->t, DDRGB(0, 0, 1));
  18. set_matrix_world(&p_cam->p_objekt->m);
  19. kresli_objekt_dratove_jednoduse(p_cam->p_target);
  20. kresli_objekt_dratove_jednoduse(p_cam->p_pos);
  21. if (pyr) {
  22. kresli_objekt_dratove_jednoduse(p_cam->p_objekt);
  23. }
  24. }
  25. // kresli editacni flary (kostky)
  26. void oe_kresli_edit_flare(K_EDITOR * p_cnf, LENS_FLARE * p_flare, int num)
  27. {
  28. BOD p = { 0, 0, 0 };
  29. int f;
  30. text_off(GL_TEXTURE_2D);
  31. text_off(GL_TEXTURE_1D);
  32. for (f = 0; f < num; f++) {
  33. if (p_flare[f].akt) {
  34. if (p_flare[f].p_svetlo)
  35. oe_cti_pozici_static_light(p_flare[f].p_svetlo, &p);
  36. else
  37. p = p_flare[f].p;
  38. if (f == p_cnf->flareakt) {
  39. oe_test_kriz_stred_bod(p_cnf, VELIKOST_STREDU, &p, POPIS_OS_ON,
  40. STRED_ON, p_flare[f].rflag);
  41. }
  42. oe_kresli_kosoctverec(p_cnf, &p_cnf->init_matrix, &p, 0.5f, 1, 0, 0);
  43. }
  44. }
  45. }
  46. #define SLOZ_FLARE 14
  47. // Prevest to na integery !!!
  48. void oe_kresli_game_flare(K_EDITOR * p_cnf, LENS_FLARE * p_flare, int num)
  49. {
  50. STATIC_LIGHT *p_light;
  51. LENS_FLARE_SLOZ *p_sloz;
  52. int f, s;
  53. float pixel_z;
  54. float faktor, t;
  55. float xw, yw, zw, w, ryw, sx, sy;
  56. float xq, yq;
  57. float dx, dy;
  58. GLMATRIX m;
  59. BOD p;
  60. int x, y, maxx, maxy;
  61. int ox, oy;
  62. // disable_fog(p_cnf->ml.mlha);
  63. get_matrix_view(&x, &y, &maxx, &maxy);
  64. ox = x + (maxx >> 1);
  65. oy = y + (maxy >> 1);
  66. faktor = (float) (maxx) / 10.0f;
  67. mat_mult(p_cnf->p_camera, p_cnf->p_project, &m);
  68. /* Analyticka cast - zjistim ktere jsou viditelne
  69. */
  70. for (f = 0; f < num; f++) {
  71. p_flare[f].vid = FALSE;
  72. if (!p_flare[f].akt)
  73. continue;
  74. if (p_flare[f].p_svetlo) {
  75. oe_cti_pozici_static_light(p_flare[f].p_svetlo, &p);
  76. }
  77. else {
  78. p = p_flare[f].p;
  79. p_light = NULL;
  80. }
  81. w = 1.0f;
  82. transformuj_wbod_matici(&p.x, &p.y, &p.z, &w, &m);
  83. p_flare[f].vid = (0 < p.z && p.z < w && -w < p.x && p.x <= w && -w < p.y
  84. && p.y <= w);
  85. p_flare[f].wz = p.z; //wz musi byt vetsi nez 0 a mensi nez w
  86. if (p.z > 0.0f && (p_flare[f].vid || p_flare[f].p_sloz)) {
  87. xw = (maxx >> 1) * (p.x / w) + ox;
  88. yw = (maxy >> 1) * (p.y / w) + oy;
  89. zw = (0.5f) * (p.z / w) + 0.5f;
  90. p_flare[f].wx = xw;
  91. p_flare[f].wy = ryw = maxy - 1 - yw;
  92. if (p_flare[f].vid) {
  93. glReadPixels(ftoi(xw), ftoi(yw), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
  94. &pixel_z);
  95. p_flare[f].vid = (pixel_z >= zw);
  96. }
  97. if (p_flare[f].p_sloz) {
  98. xq = (float) ox - xw;
  99. yq = (float) oy - ryw;
  100. p_sloz = p_flare[f].p_sloz;
  101. for (s = 0; s < SLOZ_FLARE; s++) {
  102. t = p_sloz[s].vzdal;
  103. if (t > 0.0f) {
  104. t *= 1.3f;
  105. p_sloz[s].wx = sx = xw + xq * t;
  106. p_sloz[s].wy = sy = ryw + yq * t;
  107. p_sloz[s].vid = (0 <= sx && sx < maxx && 0 <= sy && sy < maxy);
  108. }
  109. }
  110. }
  111. }
  112. }
  113. /* Rendering flaru
  114. */
  115. set_matrix_2d(maxx, maxy);
  116. deph_test_set(FALSE);
  117. text_set_num(1);
  118. text_off(GL_TEXTURE_1D);
  119. text_off(GL_TEXTURE_2D);
  120. text_set_num(0);
  121. text_on(GL_TEXTURE_2D);
  122. blend_on();
  123. for (f = 0; f < num; f++) {
  124. if (p_flare[f].vid) {
  125. blend_set(GL_SRC_ALPHA, p_flare[f].alfa);
  126. // Nastavim material flaru
  127. text_set(p_flare[f].p_mat->p_text[0]->text,
  128. p_flare[f].p_mat->p_text[0]->typ);
  129. glColor4f(p_flare[f].r, p_flare[f].g, p_flare[f].b, p_flare[f].a);
  130. dx = p_flare[f].dx * faktor;
  131. dy = p_flare[f].dy * faktor;
  132. xw = p_flare[f].wx;
  133. yw = p_flare[f].wy;
  134. glBegin(GL_QUADS);
  135. glTexCoord2f(0.0f, 0.0f);
  136. glVertex3f(-dx + xw, dy + yw, 0.0f);
  137. glTexCoord2f(1.0f, 0.0f);
  138. glVertex3f(dx + xw, dy + yw, 0.0f);
  139. glTexCoord2f(1.0f, 1.0f);
  140. glVertex3f(dx + xw, -dy + yw, 0.0f);
  141. glTexCoord2f(0.0f, 1.0f);
  142. glVertex3f(-dx + xw, -dy + yw, 0.0f);
  143. glEnd();
  144. }
  145. if (p_flare[f].vid && p_flare[f].p_sloz /* && p_flare[f].wz > 0.0f */ ) {
  146. p_sloz = p_flare[f].p_sloz;
  147. for (s = 0; s < SLOZ_FLARE; s++) {
  148. if (p_sloz[s].vid) {
  149. xw = p_sloz[s].wx;
  150. yw = p_sloz[s].wy;
  151. dx = p_sloz[s].dx * faktor;
  152. dy = p_sloz[s].dy * faktor;
  153. text_set(p_sloz[s].p_mat->p_text[0]->text,
  154. p_sloz[s].p_mat->p_text[0]->typ);
  155. glColor4f(p_sloz[s].r, p_sloz[s].g, p_sloz[s].b, p_sloz[s].a);
  156. glBegin(GL_QUADS);
  157. glTexCoord2f(0.0f, 0.0f);
  158. glVertex3f(-dx + xw, dy + yw, 0.0f);
  159. glTexCoord2f(1.0f, 0.0f);
  160. glVertex3f(dx + xw, dy + yw, 0.0f);
  161. glTexCoord2f(1.0f, 1.0f);
  162. glVertex3f(dx + xw, -dy + yw, 0.0f);
  163. glTexCoord2f(0.0f, 1.0f);
  164. glVertex3f(-dx + xw, -dy + yw, 0.0f);
  165. glEnd();
  166. }
  167. }
  168. }
  169. }
  170. deph_test_set(TRUE);
  171. ret_matrix_2d();
  172. // enable_fog(p_cnf->ml.mlha);
  173. }
  174. void oe_kresli_kosoctverec(K_EDITOR * p_cnf, GLMATRIX * p_world, BOD * p_p,
  175. float r, float dr, float dg, float db)
  176. {
  177. kresli_kosoctverec(p_cnf->p_project, p_cnf->p_camera, p_world, p_p, r, dr,
  178. dg, db);
  179. }
  180. /*
  181. Kresli svetlo jako jehlan
  182. */
  183. void oe_kresli_staticke_svetlo(K_EDITOR * p_cnf, STATIC_LIGHT * p_light,
  184. int akt)
  185. {
  186. BOD s;
  187. if (p_light->akt) {
  188. oe_cti_pozici_static_light(p_light, &s);
  189. if (p_light->index == akt) {
  190. oe_test_kriz_stred_bod(p_cnf, VELIKOST_STREDU, &s, POPIS_OS_ON,
  191. STRED_ON, p_light->flag);
  192. }
  193. oe_kresli_kosoctverec(p_cnf, &p_cnf->init_matrix, &s, 0.5f, 1, 1, 0);
  194. }
  195. }
  196. /*
  197. Kresli dynamicke svetlo
  198. */
  199. void oe_kresli_dynamicke_svetlo(K_EDITOR * p_cnf, DYN_LIGHT * p_light,
  200. int akt)
  201. {
  202. BOD s;
  203. if (p_light->akt) {
  204. if (p_light->flag & SDL_MESH) {
  205. transformuj_bod_matici_bod(&p_light->np,
  206. kont_world_matrix(p_light->p_mesh_data), &s);
  207. }
  208. else {
  209. s = p_light->np;
  210. }
  211. if (akt) {
  212. oe_test_kriz_stred_bod(p_cnf, VELIKOST_STREDU, &s, POPIS_OS_ON,
  213. STRED_ON, p_light->pflag);
  214. }
  215. oe_kresli_kosoctverec(p_cnf, &p_cnf->init_matrix, &s, 0.5f, 1, 1, 0);
  216. }
  217. }
  218. /*
  219. Kresli extra svetla
  220. */
  221. void oe_kresli_extra_dynamicke_svetlo(K_EDITOR * p_cnf,
  222. EXTRA_DYN_LIGHT * p_light, int akt)
  223. {
  224. BOD s;
  225. if (p_light->akt) {
  226. if (p_light->flag & EDL_MESH) {
  227. transformuj_bod_matici_bod(&p_light->np,
  228. kont_world_matrix(p_light->p_mesh_data), &s);
  229. }
  230. else {
  231. s = p_light->np;
  232. }
  233. if (akt) {
  234. oe_test_kriz_stred_bod(p_cnf, VELIKOST_STREDU, &s, POPIS_OS_ON,
  235. STRED_ON, p_light->pflag);
  236. }
  237. oe_kresli_kosoctverec(p_cnf, &p_cnf->init_matrix, &s, 0.5f,
  238. 113.0f / 255.0f, 250.0f / 255.0f, 88.0f / 255.0f);
  239. }
  240. }
  241. /*
  242. Kresli stred levelu
  243. */
  244. void oe_kresli_stred_levelu(K_EDITOR * p_cnf)
  245. {
  246. oe_test_kriz_stred_bod(p_cnf, VELIKOST_STREDU, &p_cnf->elm.p, POPIS_OS_ON,
  247. STRED_ON, p_cnf->elm.flag);
  248. oe_kresli_kosoctverec(p_cnf, &p_cnf->init_matrix, &p_cnf->elm.p, 0.7f, 1, 0,
  249. 0);
  250. }
  251. /*
  252. - udelat grid
  253. - 2 druhy rotace
  254. - tedka delam prevedeni vseho n
  255. */
  256. void oe_kresli_mriz(float sx, float sz, float dx, int num_x, float r, float g,
  257. float b)
  258. {
  259. int vert = num_x << 1;
  260. int x, z;
  261. float p;
  262. p = dx * (num_x - 1);
  263. glColor3f(r, g, b);
  264. glBegin(GL_LINES);
  265. for (z = 0; z < vert; z += 2) {
  266. glVertex3f(sx, 0, sz + (float) (z >> 1) * dx);
  267. glVertex3f(sx + p, 0, sz + (float) (z >> 1) * dx);
  268. }
  269. p = dx * (num_x - 1);
  270. for (x = 0; x < vert; x += 2) {
  271. glVertex3f(sx + (float) (x >> 1) * dx, 0, (float) sz);
  272. glVertex3f(sx + (float) (x >> 1) * dx, 0, (float) sz + p);
  273. }
  274. glEnd();
  275. }
  276. void oe_kresli_stred(float d, float r, float g, float b)
  277. {
  278. glEnable(GL_POLYGON_OFFSET_LINE);
  279. glPolygonOffset(-20.0f, 1.0f);
  280. glColor3f(r, g, b);
  281. glBegin(GL_LINES);
  282. glVertex3f(d, 0, 0);
  283. glVertex3f(-d, 0, 0);
  284. glVertex3f(0, 0, d);
  285. glVertex3f(0, 0, -d);
  286. glEnd();
  287. glDisable(GL_POLYGON_OFFSET_LINE);
  288. }
  289. void oe_kresli_grid(K_EDITOR * p_cnf)
  290. {
  291. ROVINA r = { 0, 1, 0, 0 };
  292. BOD a, b, p, k;
  293. float x, z;
  294. float vzd;
  295. static int num_x, dx;
  296. static GLMATRIX m;
  297. if (!m._11)
  298. init_matrix(&m);
  299. set_matrix_world(&m);
  300. text_off(GL_TEXTURE_1D);
  301. text_off(GL_TEXTURE_2D);
  302. blend_off();
  303. if (p_cnf->cnf.svetla)
  304. nastav_material_rgb_MAT(&p_cnf->barva_grid);
  305. // spocitat prusek s nulovou plochou
  306. // stredovy bod obrazovky
  307. transf_2d_3d((float) OXRES / 2, (float) OYRES / 2, 0,
  308. &a.x, &a.y, &a.z,
  309. p_cnf->p_camera, p_cnf->p_project, OXRES, OYRES, OXSTART, OYSTART);
  310. transf_2d_3d((float) OXRES / 2, (float) OYRES / 2, 0.5f,
  311. &b.x, &b.y, &b.z,
  312. p_cnf->p_camera, p_cnf->p_project, OXRES, OYRES, OXSTART, OYSTART);
  313. calc_prusek_bod(&r, &a, &b, &p);
  314. // krajni bod obrazovky
  315. transf_2d_3d((float) 0, (float) OYRES, 0,
  316. &a.x, &a.y, &a.z,
  317. p_cnf->p_camera, p_cnf->p_project, OXRES, OYRES, OXSTART, OYSTART);
  318. transf_2d_3d((float) 0, (float) OYRES, 0.5f,
  319. &b.x, &b.y, &b.z,
  320. p_cnf->p_camera, p_cnf->p_project, OXRES, OYRES, OXSTART, OYSTART);
  321. calc_prusek_bod(&r, &a, &b, &k);
  322. // 2 3d body v jedne rovine
  323. // p - stredovy bod
  324. // b - krajni bod
  325. //oe_kresli_mriz_2(&k, &p, 1.0f, 0.8f, 0.8f, 0.8f);
  326. // x >>= 1; x <<= 1;
  327. // z >>= 1; z <<= 1;
  328. // oe_kresli_mriz(x-100, z-100, 2, 100, 0.8f, 0.8f, 0.8f);
  329. x = (float) ceil(p.x);
  330. z = (float) ceil(p.z);
  331. vzd = (float) ceil(vzdal_bodu_bod(&p, &k)) * 4;
  332. if (vzd < 50) {
  333. oe_kresli_mriz(x - vzd, z - vzd, 1, (int) vzd << 1, 0.8f, 0.8f, 0.8f);
  334. }
  335. else
  336. oe_kresli_mriz(x - 50, z - 50, 1, 100, 0.8f, 0.8f, 0.8f);
  337. oe_kresli_stred(5, 0, 0, 0);
  338. }
  339. void oe_kresli_linelist(K_EDITOR * p_cnf)
  340. {
  341. int i;
  342. glColor3ubv((byte *) & p_cnf->linelist_barva);
  343. glBegin(GL_LINES);
  344. for (i = 0; i < p_cnf->linelist_num; i++) {
  345. glVertex2d(p_cnf->linelist_cara[i].x1, p_cnf->linelist_cara[i].y1);
  346. glVertex2d(p_cnf->linelist_cara[i].x2, p_cnf->linelist_cara[i].y2);
  347. }
  348. glEnd();
  349. }
  350. void oe_kresli_kd_strom(KD_BUNKA * p_prvni, int uroven)
  351. {
  352. dword b = 0x0, a = 0x505050;
  353. add_mult_color(&b, a, (float) uroven);
  354. kresli_oktanovou_bunku_minmax(&p_prvni->min, &p_prvni->max, b);
  355. if (p_prvni->p_next) {
  356. oe_kresli_kd_strom(p_prvni->p_next, uroven + 1);
  357. oe_kresli_kd_strom(p_prvni->p_next + 1, uroven + 1);
  358. }
  359. }
  360. void oe_kresli_group_vertexy(K_EDITOR * p_cnf)
  361. {
  362. GLMATRIX m;
  363. float z;
  364. int o, v, x, y, i, k = K_CHYBA;
  365. int transform = 0;
  366. for (i = 0; i < p_cnf->groupnum; i++) {
  367. if (k != p_cnf->p_group[i].k) {
  368. k = p_cnf->p_group[i].k;
  369. transform++;
  370. }
  371. if (o != p_cnf->p_group[i].o) {
  372. o = p_cnf->p_group[i].o;
  373. transform++;
  374. }
  375. if (!p_cnf->p_kont[k] || !p_cnf->p_kont[k]->p_obj[o]) {
  376. oe_ungroup_vertex(p_cnf, i);
  377. continue;
  378. }
  379. v = p_cnf->p_group[i].v;
  380. if (v >= p_cnf->p_kont[k]->p_obj[o]->vertexnum) {
  381. oe_ungroup_vertex(p_cnf, i);
  382. continue;
  383. }
  384. if (transform) {
  385. if (p_cnf->p_kont[k]->kflag & KONT_KEYFRAME) {
  386. calc_3d_2d_matrix(&p_cnf->p_kont[k]->p_obj[o]->m,
  387. p_cnf->p_camera, p_cnf->p_project, &m);
  388. }
  389. else {
  390. calc_3d_2d_matrix(kont_world_matrix(p_cnf->p_kont[k]),
  391. p_cnf->p_camera, p_cnf->p_project, &m);
  392. }
  393. transform = 0;
  394. }
  395. if (transf_3d_2d_matrix(p_cnf->p_kont[k]->p_obj[o]->p_vertex[v].x,
  396. p_cnf->p_kont[k]->p_obj[o]->p_vertex[v].y,
  397. p_cnf->p_kont[k]->p_obj[o]->p_vertex[v].z,
  398. &x, &y, &z, &m, OXRES, OYRES, OXSTART, OYSTART,
  399. p_cnf->kam.near_plane, p_cnf->kam.far_plane)) {
  400. if (p_cnf->vybr_group == i)
  401. kresli_ctverec_2d_plnej(x - VEL_CTVERCE, y - VEL_CTVERCE,
  402. x + VEL_CTVERCE, y + VEL_CTVERCE, 1, 0, 0);
  403. else
  404. kresli_ctverec_2d(x - VEL_CTVERCE, y - VEL_CTVERCE, x + VEL_CTVERCE,
  405. y + VEL_CTVERCE, 1, 0, 0);
  406. }
  407. }
  408. }
  409. /*
  410. Kreslit mlho-kostku
  411. */
  412. void oe_kresli_mlho_kostky(K_EDITOR * p_cnf)
  413. {
  414. MLZNA_KOSTKA *p_mlha = p_cnf->p_mlha;
  415. GLMATRIX world;
  416. BOD s;
  417. init_matrix(&world);
  418. while (p_mlha) {
  419. kresli_oktanovou_bunku_minmax(&p_mlha->min, &p_mlha->max,
  420. float_rgba(&p_mlha->r));
  421. kd_stred_bunky(&p_mlha->min, &p_mlha->max, &s);
  422. if (p_mlha == p_cnf->p_mlha_akt)
  423. oe_kresli_kosoctverec(p_cnf, &world, &s, 0.5f, 0.0f, 1.0f, 0.0f);
  424. else
  425. oe_kresli_kosoctverec(p_cnf, &world, &s, 0.5f, 0.0f, 0.0f, 1.0f);
  426. oe_test_kriz_stred_bod(p_cnf, VELIKOST_STREDU, &s, POPIS_OS_ON, STRED_ON,
  427. p_cnf->p_mlha->flag);
  428. p_mlha = p_mlha->p_next;
  429. }
  430. }
  431. void oe_renderuj_mlho_kostky(K_EDITOR * p_cnf)
  432. {
  433. MLZNA_KOSTKA *p_mlha = p_cnf->p_mlha_akt;
  434. if (p_mlha && p_cnf->cnf.mlhokostka_aktivni && p_cnf->cnf.mlhokostka_testy) {
  435. if (kd_je_bod_v_kostce((BOD *) & p_cnf->p_invcam->_41, &p_mlha->min,
  436. &p_mlha->max))
  437. enable_fog();
  438. else
  439. disable_fog();
  440. }
  441. }
  442. void oe_kresli_bb_kamery(K_EDITOR * p_cnf)
  443. {
  444. float r[4] = { 1, 1, 1, 1 };
  445. int flag = POSUN_OSA_X | POSUN_OSA_Y | POSUN_OSA_Z;
  446. GLMATRIX world;
  447. BOD s;
  448. init_matrix(&world);
  449. kresli_oktanovou_bunku_minmax(&p_cnf->kam.min, &p_cnf->kam.max,
  450. float_rgba(r));
  451. kd_stred_bunky(&p_cnf->kam.min, &p_cnf->kam.max, &s);
  452. oe_kresli_kosoctverec(p_cnf, &world, &s, 0.5f, 0.0f, 0.0f, 1.0f);
  453. oe_test_kriz_stred_bod(p_cnf, VELIKOST_STREDU, &s, POPIS_OS_ON, STRED_ON,
  454. flag);
  455. }
  456. /*
  457. Grop-vertexy pro plosky
  458. */
  459. void oe_kresli_group_face(K_EDITOR * p_cnf)
  460. {
  461. EDIT_KONTEJNER *p_kont;
  462. int i, k, o, f;
  463. int flag = p_cnf->groupflag;
  464. glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  465. glEnable(GL_POLYGON_OFFSET_LINE);
  466. glPolygonOffset(-20.0f, 1.0f);
  467. if (flag & GROUP_KONT && !(flag & (GROUP_OBJ | GROUP_FACE))) {
  468. for (i = 0; i < p_cnf->groupfacenum; i++) {
  469. k = p_cnf->p_group_face[i].k;
  470. if ((p_kont = p_cnf->p_kont[k])) {
  471. obb_kresli_obalku_kont(p_kont, kont_world_matrix(p_kont), DDRGB(0, 1,
  472. 0));
  473. }
  474. }
  475. }
  476. else if (flag & GROUP_KONT && flag & GROUP_OBJ && !(flag & GROUP_FACE)) {
  477. for (i = 0; i < p_cnf->groupfacenum; i++) {
  478. k = p_cnf->p_group_face[i].k;
  479. o = p_cnf->p_group_face[i].o;
  480. p_kont = p_cnf->p_kont[k];
  481. if (p_kont && p_kont->p_obj[o]) {
  482. obb_kresli_obalku_obj(p_kont->p_obj[o], kont_world_matrix(p_kont),
  483. DDRGB(0, 1, 0));
  484. }
  485. }
  486. }
  487. else if (flag & GROUP_KONT && flag & GROUP_OBJ && flag & GROUP_FACE) {
  488. glColor3f(0.0f, 1.0f, 0.0f);
  489. for (i = 0; i < p_cnf->groupfacenum; i++) {
  490. k = p_cnf->p_group_face[i].k;
  491. o = p_cnf->p_group_face[i].o;
  492. f = p_cnf->p_group_face[i].f;
  493. p_kont = p_cnf->p_kont[k];
  494. if (p_kont && p_kont->p_obj[o]) {
  495. set_matrix_world(kont_world_matrix(p_kont));
  496. oe_kresli_face(p_kont->p_obj[o], f);
  497. }
  498. }
  499. }
  500. glDisable(GL_POLYGON_OFFSET_LINE);
  501. glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  502. }
  503. void oe_kresli_d_vertexy(K_EDITOR * p_cnf)
  504. {
  505. GLMATRIX m, m2;
  506. int i;
  507. float z;
  508. int x, y, f = 0;
  509. calc_3d_2d_matrix(init_matrix(&m2), p_cnf->p_camera, p_cnf->p_project, &m);
  510. for (i = 0; i < p_cnf->dvertnum; i++) {
  511. if (p_cnf->p_dvert[i].d2) {
  512. x = (int) p_cnf->p_dvert[i].x;
  513. y = (int) p_cnf->p_dvert[i].y;
  514. if (p_cnf->vybr_dvert == i)
  515. kresli_ctverec_2d_plnej(x - VEL_CTVERCE, y - VEL_CTVERCE,
  516. x + VEL_CTVERCE, y + VEL_CTVERCE, 0, 1, 0);
  517. else
  518. kresli_ctverec_2d(x - VEL_CTVERCE, y - VEL_CTVERCE, x + VEL_CTVERCE,
  519. y + VEL_CTVERCE, 0, 1, 0);
  520. }
  521. else {
  522. if (transf_3d_2d_matrix(p_cnf->p_dvert[i].x, p_cnf->p_dvert[i].y,
  523. p_cnf->p_dvert[i].z, &x, &y, &z, &m, OXRES, OYRES, OXSTART, OYSTART,
  524. p_cnf->kam.near_plane, p_cnf->kam.far_plane)) {
  525. if (p_cnf->vybr_dvert == i)
  526. kresli_ctverec_2d_plnej(x - VEL_CTVERCE, y - VEL_CTVERCE,
  527. x + VEL_CTVERCE, y + VEL_CTVERCE, 0, 1, 0);
  528. else
  529. kresli_ctverec_2d(x - VEL_CTVERCE, y - VEL_CTVERCE, x + VEL_CTVERCE,
  530. y + VEL_CTVERCE, 0, 1, 0);
  531. }
  532. }
  533. }
  534. }
  535. /* Objektovy env mapping
  536. */
  537. void oe_obj_env_spec(EDIT_MATERIAL * p_mat, EDIT_OBJEKT * p_obj,
  538. GLMATRIX * p_kw)
  539. {
  540. MUJ_BOD *p_bod;
  541. int os = p_mat->flag2 & MAT2_ENV_SPEC_OBE;
  542. int v;
  543. float tx, ty, tz;
  544. float px, py, pz;
  545. float v1, v2, v3;
  546. float uhel;
  547. float r, g, b;
  548. float rr, rg, rb;
  549. rr = p_mat->env_r;
  550. rg = p_mat->env_g;
  551. rb = p_mat->env_b;
  552. // z vektor pohledu - optimalizace!
  553. v1 = p_cnf->p_camera->_13;
  554. v2 = p_cnf->p_camera->_23;
  555. v3 = p_cnf->p_camera->_33;
  556. norm_vect(&v1, &v2, &v3);
  557. p_bod = p_obj->p_vertex;
  558. for (v = 0; v < p_obj->vertexnum; v++) {
  559. px = p_bod[v].nx;
  560. py = p_bod[v].ny;
  561. pz = p_bod[v].nz;
  562. tx = p_kw->_11 * px + p_kw->_21 * py + p_kw->_31 * pz;
  563. ty = p_kw->_12 * px + p_kw->_22 * py + p_kw->_32 * pz;
  564. tz = p_kw->_13 * px + p_kw->_23 * py + p_kw->_33 * pz;
  565. norm_vect(&tx, &ty, &tz);
  566. uhel = tx * v1 + ty * v2 + tz * v3;
  567. uhel = (p_mat->env_scale * (p_mat->env_add1 + uhel)) + p_mat->env_add2;
  568. // uhel je od 0 - 1
  569. //
  570. //uhel += (rand()%1000)*0.0001f;
  571. if (os) {
  572. uhel = fabsf(uhel);
  573. r = (rr * uhel > 1.0f) ? 1.0f : rr * uhel;
  574. g = (rg * uhel > 1.0f) ? 1.0f : rg * uhel;
  575. b = (rb * uhel > 1.0f) ? 1.0f : rb * uhel;
  576. }
  577. else {
  578. if (uhel > 0) {
  579. r = (rr * uhel > 1.0f) ? 1.0f : rr * uhel;
  580. g = (rg * uhel > 1.0f) ? 1.0f : rg * uhel;
  581. b = (rb * uhel > 1.0f) ? 1.0f : rb * uhel;
  582. }
  583. else {
  584. r = g = b = 0;
  585. }
  586. }
  587. p_bod[v].sr = r;
  588. p_bod[v].sg = g;
  589. p_bod[v].sb = b;
  590. }
  591. }
  592. void oe_poly_env_spec(EDIT_MATERIAL * p_mat, EDIT_MESH_POLY * p_poly)
  593. {
  594. poly_env_maping_spec(p_poly, p_mat, p_cnf->p_camera);
  595. }
  596. void oe_animuj_frame_material(dword akt_time, EDIT_MATERIAL * p_mat,
  597. EDIT_TEXT * p_text)
  598. {
  599. ANIM_MATERIAL *p_anim = &p_mat->anim;
  600. ANIM_FRAME *p_frame;
  601. int next_frame;
  602. dword flag;
  603. if (p_anim->frameakt >= p_anim->framenum)
  604. p_anim->frameakt = 0;
  605. next_frame = p_anim->frameakt;
  606. flag = p_anim->p_frame[next_frame].flag;
  607. p_frame = p_anim->p_frame + next_frame;
  608. if (p_anim->last_time + p_anim->p_frame[next_frame].time < akt_time
  609. && !(flag & FRAME_EVENT)) {
  610. if (flag & FRAME_TEXTURA)
  611. p_mat->p_text[0] = p_frame->p_text;
  612. if (flag & FRAME_POSUN) {
  613. p_mat->ttext[0]._41 = p_frame->u;
  614. p_mat->ttext[0]._42 = p_frame->v;
  615. }
  616. p_anim->last_time = akt_time;
  617. p_anim->frameakt++;
  618. }
  619. }
  620. void oe_animuj_frame_material_event(dword akt_time, EDIT_MATERIAL * p_mat,
  621. EDIT_TEXT * p_text)
  622. {
  623. ANIM_MATERIAL *p_anim = &p_mat->anim;
  624. ANIM_FRAME *p_frame;
  625. int next_frame;
  626. dword flag;
  627. if (p_anim->frameakt >= p_anim->framenum)
  628. p_anim->frameakt = 0;
  629. next_frame = p_anim->frameakt;
  630. flag = p_anim->p_frame[next_frame].flag;
  631. p_frame = p_anim->p_frame + next_frame;
  632. if (flag & FRAME_EVENT) {
  633. if (flag & FRAME_TEXTURA)
  634. p_mat->p_text[0] = p_anim->p_frame[next_frame].p_text;
  635. if (flag & FRAME_POSUN) {
  636. p_mat->ttext[0]._41 = p_frame->u;
  637. p_mat->ttext[0]._42 = p_frame->v;
  638. }
  639. p_anim->last_time = akt_time;
  640. p_anim->frameakt++;
  641. }
  642. }
  643. void oe_animuj_materialy(K_EDITOR * p_cnf, byte event)
  644. {
  645. int m;
  646. if (!event) {
  647. for (m = 0; m < MAX_EDIT_MATERIALU; m++) {
  648. if (p_cnf->p_mat[m] && p_cnf->p_mat[m]->flag & MAT_ANIM_FRAME)
  649. oe_animuj_frame_material(p_cnf->TimeEndLastFrame, p_cnf->p_mat[m],
  650. p_cnf->p_text);
  651. }
  652. }
  653. else {
  654. for (m = 0; m < MAX_EDIT_MATERIALU; m++) {
  655. if (p_cnf->p_mat[m] && p_cnf->p_mat[m]->flag & MAT_ANIM_FRAME)
  656. oe_animuj_frame_material_event(p_cnf->TimeEndLastFrame,
  657. p_cnf->p_mat[m], p_cnf->p_text);
  658. }
  659. }
  660. }
  661. void oe_init_animace_materialy(K_EDITOR * p_cnf)
  662. {
  663. int m;
  664. for (m = 0; m < MAX_EDIT_MATERIALU; m++) {
  665. if (p_cnf->p_mat[m] && p_cnf->p_mat[m]->flag & MAT_ANIM_FRAME) {
  666. p_cnf->p_mat[m]->anim.frameakt = 0;
  667. p_cnf->p_mat[m]->anim.last_time = p_cnf->TimeLastFrame;
  668. p_cnf->p_mat[m]->p_text[0] = p_cnf->p_mat[m]->anim.p_frame[0].p_text;
  669. }
  670. }
  671. }
  672. void oe_kresli_objekt_jednoduse(EDIT_OBJEKT * p_obj, int flag, int kflag)
  673. {
  674. int i, f1, f2, f3, ind, *p_int;
  675. int kalk1 = flag & MAT2_MAP1;
  676. int kalk2 = flag & MAT2_MAP2;
  677. int kalk3 = flag & MAT2_MAP3;
  678. int kalk4 = flag & MAT2_MAP4;
  679. int norm = glstav_pn_triangles
  680. || flag & (MAT2_CALC_MAP1 | MAT2_CALC_MAP2 | MAT2_CALC_MAP3 |
  681. MAT2_CALC_MAP4);
  682. int scale = kflag & KONT_NORMAL_ANIM && p_obj->float_scale != 0.0f;
  683. glBegin(GL_TRIANGLES);
  684. for (i = 0; i < p_obj->facenum; i += 3) {
  685. f1 = p_obj->p_face[i];
  686. f2 = p_obj->p_face[i + 1];
  687. f3 = p_obj->p_face[i + 2];
  688. p_int = glstav_text_map_indicie;
  689. if ((ind = *p_int) != K_CHYBA)
  690. glMultiTexCoord2fvARB(GL_TEXTURE0_ARB,
  691. ((float *) (&p_obj->p_vertex[f1].tu1)) + ((ind) << 1));
  692. p_int++;
  693. if ((ind = *p_int) != K_CHYBA)
  694. glMultiTexCoord2fvARB(GL_TEXTURE1_ARB,
  695. ((float *) (&p_obj->p_vertex[f1].tu1)) + ((ind) << 1));
  696. p_int++;
  697. if ((ind = *p_int) != K_CHYBA)
  698. glMultiTexCoord2fvARB(GL_TEXTURE2_ARB,
  699. ((float *) (&p_obj->p_vertex[f1].tu1)) + ((ind) << 1));
  700. p_int++;
  701. if ((ind = *p_int) != K_CHYBA)
  702. glMultiTexCoord2fvARB(GL_TEXTURE3_ARB,
  703. ((float *) (&p_obj->p_vertex[f1].tu1)) + ((ind) << 1));
  704. if (norm)
  705. glNormal3fv(&p_obj->p_vertex[f1].nx);
  706. glColor4fv(&p_obj->p_vertex[f1].dr);
  707. glSecondaryColor3fvEXT(&p_obj->p_vertex[f1].sr);
  708. glVertex3fv(p_obj->p_vertex_kosti ? (float *) (p_obj->p_vertex_kosti +
  709. f1) : &p_obj->p_vertex[f1].x);
  710. p_int = glstav_text_map_indicie;
  711. if ((ind = *p_int) != K_CHYBA)
  712. glMultiTexCoord2fvARB(GL_TEXTURE0_ARB,
  713. ((float *) (&p_obj->p_vertex[f2].tu1)) + ((ind) << 1));
  714. p_int++;
  715. if ((ind = *p_int) != K_CHYBA)
  716. glMultiTexCoord2fvARB(GL_TEXTURE1_ARB,
  717. ((float *) (&p_obj->p_vertex[f2].tu1)) + ((ind) << 1));
  718. p_int++;
  719. if ((ind = *p_int) != K_CHYBA)
  720. glMultiTexCoord2fvARB(GL_TEXTURE2_ARB,
  721. ((float *) (&p_obj->p_vertex[f2].tu1)) + ((ind) << 1));
  722. p_int++;
  723. if ((ind = *p_int) != K_CHYBA)
  724. glMultiTexCoord2fvARB(GL_TEXTURE3_ARB,
  725. ((float *) (&p_obj->p_vertex[f2].tu1)) + ((ind) << 1));
  726. if (norm)
  727. glNormal3fv(&p_obj->p_vertex[f2].nx);
  728. glColor4fv(&p_obj->p_vertex[f2].dr);
  729. glSecondaryColor3fvEXT(&p_obj->p_vertex[f2].sr);
  730. glVertex3fv(p_obj->p_vertex_kosti ? (float *) (p_obj->p_vertex_kosti +
  731. f2) : &p_obj->p_vertex[f2].x);
  732. p_int = glstav_text_map_indicie;
  733. if ((ind = *p_int) != K_CHYBA)
  734. glMultiTexCoord2fvARB(GL_TEXTURE0_ARB,
  735. ((float *) (&p_obj->p_vertex[f3].tu1)) + ((ind) << 1));
  736. p_int++;
  737. if ((ind = *p_int) != K_CHYBA)
  738. glMultiTexCoord2fvARB(GL_TEXTURE1_ARB,
  739. ((float *) (&p_obj->p_vertex[f3].tu1)) + ((ind) << 1));
  740. p_int++;
  741. if ((ind = *p_int) != K_CHYBA)
  742. glMultiTexCoord2fvARB(GL_TEXTURE2_ARB,
  743. ((float *) (&p_obj->p_vertex[f3].tu1)) + ((ind) << 1));
  744. p_int++;
  745. if ((ind = *p_int) != K_CHYBA)
  746. glMultiTexCoord2fvARB(GL_TEXTURE3_ARB,
  747. ((float *) (&p_obj->p_vertex[f3].tu1)) + ((ind) << 1));
  748. if (norm)
  749. glNormal3fv(&p_obj->p_vertex[f3].nx);
  750. glColor4fv(&p_obj->p_vertex[f3].dr);
  751. glSecondaryColor3fvEXT(&p_obj->p_vertex[f3].sr);
  752. glVertex3fv(p_obj->p_vertex_kosti ? (float *) (p_obj->p_vertex_kosti +
  753. f3) : &p_obj->p_vertex[f3].x);
  754. }
  755. glEnd();
  756. }
  757. void oe_kresli_objekt_jednoduse_normal(EDIT_OBJEKT * p_obj, float dv)
  758. {
  759. int i, f1, f2, f3;
  760. BOD v;
  761. glBegin(GL_LINES);
  762. for (i = 0; i < p_obj->facenum; i += 3) {
  763. f1 = p_obj->p_face[i];
  764. f2 = p_obj->p_face[i + 1];
  765. f3 = p_obj->p_face[i + 2];
  766. glColor3f(0, 1, 0);
  767. if (p_obj->p_vertex_kosti) {
  768. v = p_obj->p_vertex_kosti[f1];
  769. }
  770. else {
  771. mujbod2bod(&v, p_obj->p_vertex + f1);
  772. }
  773. glVertex3fv((float *) &v);
  774. glVertex3f(-p_obj->p_vertex[f1].nx * dv + v.x,
  775. -p_obj->p_vertex[f1].ny * dv + v.y, -p_obj->p_vertex[f1].nz * dv + v.z);
  776. glColor3f(0, 1, 0);
  777. if (p_obj->p_vertex_kosti) {
  778. v = p_obj->p_vertex_kosti[f2];
  779. }
  780. else {
  781. mujbod2bod(&v, p_obj->p_vertex + f2);
  782. }
  783. glVertex3fv((float *) &v);
  784. glVertex3f(-p_obj->p_vertex[f2].nx * dv + v.x,
  785. -p_obj->p_vertex[f2].ny * dv + v.y, -p_obj->p_vertex[f2].nz * dv + v.z);
  786. glColor3f(0, 1, 0);
  787. if (p_obj->p_vertex_kosti) {
  788. v = p_obj->p_vertex_kosti[f3];
  789. }
  790. else {
  791. mujbod2bod(&v, p_obj->p_vertex + f3);
  792. }
  793. glVertex3fv((float *) &v);
  794. glVertex3f(-p_obj->p_vertex[f3].nx * dv + v.x,
  795. -p_obj->p_vertex[f3].ny * dv + v.y, -p_obj->p_vertex[f3].nz * dv + v.z);
  796. }
  797. glEnd();
  798. }
  799. void oe_kresli_face(EDIT_OBJEKT * p_obj, int face)
  800. {
  801. if (p_obj->face_typ == GL_TRIANGLES && face < p_obj->facenum - 2) {
  802. glBegin(GL_TRIANGLES);
  803. glVertex3f(p_obj->p_vertex[p_obj->p_face[face]].x,
  804. p_obj->p_vertex[p_obj->p_face[face]].y,
  805. p_obj->p_vertex[p_obj->p_face[face]].z);
  806. glVertex3f(p_obj->p_vertex[p_obj->p_face[face + 1]].x,
  807. p_obj->p_vertex[p_obj->p_face[face + 1]].y,
  808. p_obj->p_vertex[p_obj->p_face[face + 1]].z);
  809. glVertex3f(p_obj->p_vertex[p_obj->p_face[face + 2]].x,
  810. p_obj->p_vertex[p_obj->p_face[face + 2]].y,
  811. p_obj->p_vertex[p_obj->p_face[face + 2]].z);
  812. glEnd();
  813. }
  814. }
  815. // Nastavi material se scene-materialem
  816. void oe_nastav_material_single(EDIT_MATERIAL * p_smat, EDIT_MATERIAL * p_mat,
  817. EDIT_OBJEKT * p_obj, GLMATRIX * p_world)
  818. {
  819. MATERIAL_TEXT *p_stg;
  820. MATERIAL_TEXT *p_stg_smat;
  821. int i, s, t, rezerva_smat, rezerva_mat, pozice_smat, stage_smat;
  822. if (!p_mat)
  823. return;
  824. /* Alfa-blending - z puvodni funkce
  825. */
  826. p_alfa_stage_func[p_mat->alfa_state] ();
  827. /* Je to nekde uprostred - nastav rezervu
  828. */
  829. if (!p_smat || p_mat->flag & MAT_NO_SCMT) {
  830. p_stg = p_mat->text_state;
  831. t = 0;
  832. for (i = 0; i < MAT_TEXTUR; i++) {
  833. if ((s = p_stg->text_stage) != K_CHYBA) {
  834. if ((t =
  835. p_text_stage_func[s] (p_mat, text_stage_edit_blok + s, p_stg, t,
  836. 0)) == K_CHYBA)
  837. break;
  838. }
  839. else { // defaultni stage - nic
  840. text_stage_func_nic(t);
  841. break;
  842. }
  843. p_stg++;
  844. }
  845. }
  846. else {
  847. p_stg = p_mat->text_state;
  848. p_stg_smat = p_smat->text_state;
  849. pozice_smat = p_smat->smaterial_pozice;
  850. stage_smat = p_stg_smat->text_stage;
  851. if (p_smat->flag & MAT_SCENE_NUTNY) {
  852. rezerva_smat = p_smat->textur;
  853. rezerva_mat = 0;
  854. }
  855. else {
  856. rezerva_smat = 0;
  857. rezerva_mat = p_mat->textur;
  858. }
  859. t = 0;
  860. for (i = 0; i < MAT_TEXTUR; i++) {
  861. if (i == pozice_smat) {
  862. if ((t =
  863. p_text_stage_func[stage_smat] (p_smat,
  864. text_stage_edit_blok + stage_smat, p_stg_smat, t,
  865. rezerva_mat)) == K_CHYBA)
  866. break;
  867. rezerva_smat = 0;
  868. }
  869. if ((s = p_stg->text_stage) != K_CHYBA) {
  870. if ((t =
  871. p_text_stage_func[s] (p_mat, text_stage_edit_blok + s, p_stg, t,
  872. rezerva_smat)) == K_CHYBA)
  873. break;
  874. }
  875. else { // defaultni stage - nic - konec
  876. break;
  877. }
  878. p_stg++;
  879. }
  880. if (i < pozice_smat) {
  881. t =
  882. p_text_stage_func[stage_smat] (p_smat,
  883. text_stage_edit_blok + stage_smat, p_stg_smat, t, 0);
  884. }
  885. text_stage_func_nic(t);
  886. }
  887. /* Nastaveni difusni barvy
  888. */
  889. if (p_mat->flag2 & MAT2_DIFFUSE) {
  890. diffuse_on();
  891. }
  892. else {
  893. diffuse_off(p_mat->dxmat.diffuse_r, p_mat->dxmat.diffuse_g,
  894. p_mat->dxmat.diffuse_b, p_mat->dxmat.diffuse_a);
  895. }
  896. /* Nastaveni spekularni barvy
  897. */
  898. if (p_mat->flag2 & MAT2_SPECULAR)
  899. specular_on();
  900. else
  901. specular_off();
  902. if (p_mat->flag2 & MAT2_ENV_SPEC && p_world) {
  903. specular_on();
  904. oe_obj_env_spec(p_mat, p_obj, p_world);
  905. }
  906. /* Nastaveni z-bufferu
  907. */
  908. if (p_mat->flag & MAT_NO_ZTEST)
  909. glDisable(GL_DEPTH_TEST);
  910. deph_test_set((~p_mat->flag) & MAT_NO_ZMASK);
  911. /* Nastaveni cullingu
  912. */
  913. if (p_cnf->cul) {
  914. if (p_mat->flag & MAT_NO_CULL)
  915. cull_off();
  916. else
  917. cull_on();
  918. }
  919. }
  920. void oe_zrus_material_single(EDIT_MATERIAL * p_mat)
  921. {
  922. /* Vyrus z-test
  923. */
  924. if (!p_mat)
  925. return;
  926. /* Alfa-blending
  927. */
  928. p_alfa_stage_func[0] ();
  929. /* Texturing
  930. */
  931. text_stage_func_nic(0);
  932. if (p_mat->flag & MAT_NO_ZTEST)
  933. glEnable(GL_DEPTH_TEST);
  934. if (p_mat->flag & MAT_NO_ZMASK)
  935. deph_test_set(p_mat->flag & MAT_NO_ZMASK);
  936. }
  937. /*
  938. Vraci pocet textur na sobe
  939. */
  940. int oe_nastav_material_single_poly(EDIT_MATERIAL * p_smat,
  941. EDIT_MATERIAL * p_mat, EDIT_MESH_POLY * p_poly)
  942. {
  943. MATERIAL_TEXT *p_stg;
  944. MATERIAL_TEXT *p_stg_smat;
  945. int i, s, t, rezerva_smat, rezerva_mat, pozice_smat, stage_smat, poly_text;
  946. int text_num = 1;
  947. if (!p_mat)
  948. return (FALSE);
  949. /* Alfa-blending
  950. */
  951. p_alfa_stage_func[p_mat->alfa_state] ();
  952. /* Texturing
  953. */
  954. if (!p_smat || p_mat->flag & MAT_NO_SCMT) {
  955. p_stg = p_mat->text_state;
  956. t = 0;
  957. for (i = 0; i < MAT_TEXTUR; i++) {
  958. if ((s = p_stg->text_stage) != K_CHYBA) {
  959. if ((t =
  960. p_text_stage_func[s] (p_mat, text_stage_edit_blok + s, p_stg, t,
  961. 1)) == K_CHYBA)
  962. break;
  963. }
  964. else { // defaultni stage - nic
  965. text_stage_func_nic_poly(t + 1, t);
  966. break;
  967. }
  968. p_stg++;
  969. }
  970. }
  971. else {
  972. p_stg = p_mat->text_state;
  973. p_stg_smat = p_smat->text_state;
  974. pozice_smat = p_smat->smaterial_pozice;
  975. stage_smat = p_stg_smat->text_stage;
  976. if (p_smat->flag & MAT_SCENE_NUTNY) {
  977. rezerva_smat = p_smat->textur + 1;
  978. rezerva_mat = 1;
  979. }
  980. else {
  981. rezerva_smat = 1;
  982. rezerva_mat = p_mat->textur + 1;
  983. }
  984. t = 0;
  985. for (i = 0; i < MAT_TEXTUR; i++) {
  986. if (i == pozice_smat) {
  987. if ((t =
  988. p_text_stage_func[stage_smat] (p_smat,
  989. text_stage_edit_blok + stage_smat, p_stg_smat, t,
  990. rezerva_mat)) == K_CHYBA)
  991. break;
  992. rezerva_smat = 1;
  993. }
  994. if ((s = p_stg->text_stage) != K_CHYBA) {
  995. if ((t =
  996. p_text_stage_func[s] (p_mat, text_stage_edit_blok + s, p_stg, t,
  997. rezerva_smat)) == K_CHYBA)
  998. break;
  999. }
  1000. else { // defaultni stage - nic - konec
  1001. break;
  1002. }
  1003. p_stg++;
  1004. }
  1005. poly_text = t++;
  1006. if (i < pozice_smat) {
  1007. t =
  1008. p_text_stage_func[stage_smat] (p_smat,
  1009. text_stage_edit_blok + stage_smat, p_stg_smat, t, 1);
  1010. }
  1011. text_stage_func_nic_poly(t, poly_text);
  1012. }
  1013. /* Nastaveni difusni barvy
  1014. */
  1015. if (p_mat->flag2 & MAT2_DIFFUSE) {
  1016. diffuse_on();
  1017. }
  1018. else {
  1019. diffuse_off(p_mat->dxmat.diffuse_r, p_mat->dxmat.diffuse_g,
  1020. p_mat->dxmat.diffuse_b, p_mat->dxmat.diffuse_a);
  1021. }
  1022. /* Nastaveni spekularni barvy
  1023. */
  1024. if (p_mat->flag2 & MAT2_SPECULAR)
  1025. specular_on();
  1026. else
  1027. specular_off();
  1028. /* Spekularni env mapping
  1029. */
  1030. if (p_mat->flag2 & MAT2_ENV_SPEC) {
  1031. specular_on();
  1032. oe_poly_env_spec(p_mat, p_poly);
  1033. }
  1034. /* Nastaveni z-bufferu
  1035. */
  1036. if (p_mat->flag & MAT_NO_ZTEST)
  1037. glDisable(GL_DEPTH_TEST);
  1038. deph_test_set((~p_mat->flag) & MAT_NO_ZMASK);
  1039. /* Nastaveni cullingu
  1040. */
  1041. if (p_cnf->cul) {
  1042. if (p_mat->flag & MAT_NO_CULL)
  1043. cull_off();
  1044. else
  1045. cull_on();
  1046. }
  1047. return (text_num);
  1048. }
  1049. #define VEL_CTVERCE_KOST 2
  1050. void oe_kresli_objekt_kosti_rec_body(K_EDITOR * p_cnf,
  1051. EDIT_KONTEJNER * p_kont, EDIT_OBJEKT * p_obj, JOINT * p_joint)
  1052. {
  1053. GLMATRIX m;
  1054. int *p_ind = p_joint->p_vertexlist;
  1055. BOD *p_vert, p;
  1056. int v, x, y;
  1057. float z;
  1058. set_matrix_2d(OXRES, OYRES);
  1059. calc_3d_2d_matrix(p_kont->kflag & KONT_KEYFRAME ? &p_obj->
  1060. m : kont_world_matrix(p_kont), p_cnf->p_camera, p_cnf->p_project, &m);
  1061. for (v = 0; v < p_joint->vertexnum; v++) {
  1062. p_vert = (BOD *) (p_obj->p_vertex + p_ind[v]);
  1063. transformuj_bod_matici_bod(p_vert, &p_joint->m, &p);
  1064. if (transf_3d_2d_matrix(p.x, p.y, p.z, &x, &y, &z, &m, OXRES, OYRES,
  1065. OXSTART, OYSTART, p_cnf->kam.near_plane, p_cnf->kam.far_plane)) {
  1066. kresli_ctverec_2d_plnej(x - VEL_CTVERCE_KOST, y - VEL_CTVERCE_KOST,
  1067. x + VEL_CTVERCE_KOST, y + VEL_CTVERCE_KOST, 1, 0, 0);
  1068. }
  1069. }
  1070. ret_matrix_2d();
  1071. }
  1072. // pivot point root-jointu
  1073. void oe_kresli_objekt_kosti_rec(K_EDITOR * p_cnf, BOD * p_bod,
  1074. EDIT_KONTEJNER * p_kont, EDIT_OBJEKT * p_obj, JOINT * p_joint)
  1075. {
  1076. BOD p;
  1077. if (!p_joint)
  1078. return;
  1079. p = p_joint->pivot;
  1080. transformuj_bod_bod_matici(&p, &p_joint->m);
  1081. if (p_bod) {
  1082. kresli_caru(p_bod, &p, BARVA_KOSTI);
  1083. }
  1084. kresli_kosoctverec_word(&p, RADIUS_KOSTI,
  1085. p_cnf->jcf.p_joint_akt == p_joint ? BARVA_KOSTI_AKT : BARVA_KOSTI);
  1086. // kresli body aktualni kosti
  1087. if (p_cnf->jcf.p_joint_akt == p_joint) {
  1088. oe_kresli_objekt_kosti_rec_body(p_cnf, p_kont, p_obj, p_joint);
  1089. }
  1090. if (p_joint->p_next)
  1091. oe_kresli_objekt_kosti_rec(p_cnf, p_bod, p_kont, p_obj, p_joint->p_next);
  1092. if (p_joint->p_child)
  1093. oe_kresli_objekt_kosti_rec(p_cnf, &p, p_kont, p_obj, p_joint->p_child);
  1094. }
  1095. void oe_kresli_objekt_kosti(K_EDITOR * p_cnf, EDIT_KONTEJNER * p_kont,
  1096. EDIT_OBJEKT * p_obj)
  1097. {
  1098. EDIT_OBJEKT *p_jobj = oe_cti_joint_objekt(p_cnf);
  1099. if (p_jobj == p_obj && p_cnf->jcf.p_joint_animace_akt) {
  1100. oe_kresli_objekt_kosti_rec(p_cnf, NULL, p_kont, p_obj,
  1101. p_cnf->jcf.p_joint_animace_akt->p_child);
  1102. }
  1103. else if (p_obj->p_joit_animace) {
  1104. oe_kresli_objekt_kosti_rec(p_cnf, NULL, p_kont, p_obj,
  1105. p_obj->p_joit_animace->p_child);
  1106. }
  1107. }
  1108. void oe_kresli_objekt(K_EDITOR * p_cnf, EDIT_KONTEJNER * p_kont,
  1109. EDIT_OBJEKT * p_obj, EDIT_MATERIAL ** p_mat, int akt_objekt, int akt_kont)
  1110. {
  1111. GLMATRIX *p_word =
  1112. p_kont->kflag & KONT_KEYFRAME ? &p_obj->m : kont_world_matrix(p_kont);
  1113. int flag2;
  1114. /* Rendering obalky
  1115. */
  1116. if (p_cnf->cnf.obalky_objekt && akt_kont && akt_objekt) {
  1117. obb_kresli_obalku_obj(p_obj, NULL, DDRGB(1, 1, 1));
  1118. }
  1119. /* Nastav material
  1120. */
  1121. oe_nastav_material_single(p_cnf->p_smat ? *(p_cnf->p_smat) : NULL,
  1122. p_mat[p_obj->material], p_obj, p_word);
  1123. /* Rendering
  1124. */
  1125. flag2 = p_mat[p_obj->material] ? p_mat[p_obj->material]->flag2 : FALSE;
  1126. oe_kresli_objekt_jednoduse(p_obj, flag2, p_kont->kflag);
  1127. /* Zrusi nastaveni materialu
  1128. */
  1129. oe_zrus_material_single(p_mat[p_obj->material]);
  1130. }
  1131. EDIT_OBJEKT *oe_cti_joint_objekt(K_EDITOR * p_cnf)
  1132. {
  1133. int k = p_cnf->jcf.k;
  1134. int o = p_cnf->jcf.o;
  1135. return ((p_cnf->p_kont[k]
  1136. && p_cnf->p_kont[k]->p_obj[o]) ? p_cnf->p_kont[k]->p_obj[o] : NULL);
  1137. }
  1138. // pokud pruhledne == true -> nekresli se pruhledne objekty
  1139. void oe_kresli_kontejner(K_EDITOR * p_cnf, EDIT_MATERIAL ** p_mat,
  1140. EDIT_KONTEJNER * p_kont, int akt_objekt)
  1141. {
  1142. EDIT_OBJEKT *p_obj;
  1143. GLMATRIX conv, *p_world = NULL;
  1144. int i, k;
  1145. if (!p_kont)
  1146. return;
  1147. k = p_kont->max_objektu;
  1148. if (p_kont->kflag & KONT_PLG_OFFSET) {
  1149. glEnable(GL_POLYGON_OFFSET_FILL);
  1150. glPolygonOffset(-1.0f, -2.0f);
  1151. }
  1152. if (p_kont->kflag & KONT_NO_FOG)
  1153. disable_fog_causal();
  1154. if (!(p_kont->kflag & KONT_KEYFRAME)) {
  1155. p_world = kont_world_matrix(p_kont);
  1156. if (p_cnf->mod_matrix_akt)
  1157. p_world = mat_mult_dir(p_world, &p_cnf->mod_matrix, &conv);
  1158. set_matrix_world(p_world);
  1159. }
  1160. if (p_cnf->cnf.obalky_kontejner && akt_objekt != K_CHYBA) {
  1161. if (!p_world) // Je to key-frame - nastav world matrix pro obalku
  1162. set_matrix_world(kont_world_matrix(p_kont));
  1163. obb_kresli_obalku_kont(p_kont, NULL, DDRGB(1, 1, 1));
  1164. }
  1165. for (i = 0; i < k; i++) {
  1166. p_obj = p_kont->p_obj[i];
  1167. if (p_obj && p_obj->kreslit) {
  1168. if (p_kont->kflag & KONT_KEYFRAME) {
  1169. p_world =
  1170. (p_cnf->mod_matrix_akt) ? mat_mult_dir(&p_obj->m,
  1171. &p_cnf->mod_matrix, &conv) : &p_obj->m;
  1172. set_matrix_world(p_world);
  1173. }
  1174. if (akt_objekt == i && p_cnf->cnf.objekt_stred) {
  1175. oe_test_kriz_stred(p_cnf, VELIKOST_STREDU, p_obj->pivot.x,
  1176. p_obj->pivot.y, p_obj->pivot.z, POPIS_OS_ON, STRED_OFF, POSUN_VSE);
  1177. }
  1178. oe_kresli_objekt(p_cnf, p_kont, p_obj, p_mat, i == akt_objekt,
  1179. akt_objekt != K_CHYBA);
  1180. oe_kresli_objekt_kosti(p_cnf, p_kont, p_obj);
  1181. }
  1182. }
  1183. if (p_kont->kflag & KONT_NO_FOG)
  1184. enable_fog_causal();
  1185. if (p_kont->kflag & KONT_PLG_OFFSET) {
  1186. glDisable(GL_POLYGON_OFFSET_FILL);
  1187. }
  1188. }
  1189. void oe_kresli_objekt_dratove(K_EDITOR * p_cnf, EDIT_MATERIAL ** p_mat,
  1190. EDIT_KONTEJNER * p_kont, EDIT_OBJEKT * p_obj, int akt_objekt, int akt_kont)
  1191. {
  1192. if (!p_obj || !p_obj->kreslit)
  1193. return;
  1194. if (!p_cnf->cnf.textury && p_cnf->cnf.obalky_objekt && akt_kont
  1195. && akt_objekt) {
  1196. obb_kresli_obalku_obj(p_obj, NULL, DDRGB(1, 0, 0));
  1197. }
  1198. oe_kresli_objekt_jednoduse(p_obj, FALSE, p_kont->kflag);
  1199. if (p_cnf->cnf.norm_vect)
  1200. oe_kresli_objekt_jednoduse_normal(p_obj, p_cnf->cnf.norm_vect_velikost);
  1201. if (akt_kont && akt_objekt) {
  1202. glColor3f(1.0f, 0.0f, 0.0f);
  1203. glPolygonOffset(-20.0f, 1.0f);
  1204. oe_kresli_face(p_obj, p_cnf->vybr_face);
  1205. glPolygonOffset(-1.0f, 1.0f);
  1206. }
  1207. }
  1208. void oe_kresli_kontejner_dratove(K_EDITOR * p_cnf, EDIT_MATERIAL ** p_mat,
  1209. EDIT_KONTEJNER * p_kont, int akt_objekt)
  1210. {
  1211. EDIT_OBJEKT *p_obj;
  1212. GLMATRIX *p_world;
  1213. int i, k = p_kont->max_objektu;
  1214. if (!p_kont || !p_kont->kreslit)
  1215. return;
  1216. if (!(p_kont->kflag & KONT_KEYFRAME)) {
  1217. p_world = kont_world_matrix(p_kont);
  1218. set_matrix_world(p_world);
  1219. }
  1220. text_set_num(0);
  1221. text_off(GL_TEXTURE_1D);
  1222. text_off(GL_TEXTURE_2D);
  1223. if (!p_cnf->cnf.textury && p_cnf->cnf.obalky_kontejner
  1224. && akt_objekt != K_CHYBA) {
  1225. obb_kresli_obalku_kont(p_kont, NULL, DDRGB(0, 1, 0));
  1226. }
  1227. glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  1228. glEnable(GL_POLYGON_OFFSET_LINE);
  1229. glPolygonOffset(-2.0f, 1.0f);
  1230. for (i = 0; i < k; i++) {
  1231. p_obj = p_kont->p_obj[i];
  1232. if (p_obj && p_obj->kreslit) {
  1233. if (p_kont->kflag & KONT_KEYFRAME) {
  1234. set_matrix_world(&p_obj->m);
  1235. }
  1236. if (p_cnf->cnf.objekt_stred)
  1237. oe_test_kriz_stred(p_cnf, VELIKOST_STREDU, p_obj->pivot.x,
  1238. p_obj->pivot.y, p_obj->pivot.z, POPIS_OS_ON, STRED_OFF, POSUN_VSE);
  1239. oe_kresli_objekt_dratove(p_cnf, p_mat, p_kont, p_obj, i == akt_objekt,
  1240. akt_objekt != K_CHYBA);
  1241. oe_kresli_objekt_kosti(p_cnf, p_kont, p_obj);
  1242. }
  1243. }
  1244. glDisable(GL_POLYGON_OFFSET_LINE);
  1245. glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  1246. }
  1247. void oe_renderuj_scenu_system_2d(K_EDITOR * p_cnf)
  1248. {
  1249. text_off(GL_TEXTURE_1D);
  1250. text_off(GL_TEXTURE_2D);
  1251. blend_off();
  1252. set_matrix_2d(OXRES, OYRES);
  1253. if (p_cnf->groupnum)
  1254. oe_kresli_group_vertexy(p_cnf);
  1255. if (p_cnf->dvertnum)
  1256. oe_kresli_d_vertexy(p_cnf);
  1257. if (p_cnf->cnf.nitkovy_kriz) {
  1258. kresli_kurzor_mysi_kriz(OXRES, OYRES);
  1259. }
  1260. if (p_cnf->ctverec) {
  1261. kresli_ctverec_2d(p_cnf->x1, p_cnf->y1, p_cnf->x2, p_cnf->y2,
  1262. p_cnf->ctverec_barva[0], p_cnf->ctverec_barva[1],
  1263. p_cnf->ctverec_barva[2]);
  1264. }
  1265. if (p_cnf->linelist) {
  1266. oe_kresli_linelist(p_cnf);
  1267. }
  1268. ret_matrix_2d();
  1269. }
  1270. void oe_renderuj_scenu_system_3d(K_EDITOR * p_cnf)
  1271. {
  1272. BOD p = { 40.0f, OYRES - 40.0f, 5.0f }, d;
  1273. int i;
  1274. /* Kresli znacku modu
  1275. */
  1276. transf_2d_3d_z(p.x, p.y, p.z, &d.x, &d.y, &d.z, p_cnf->p_camera,
  1277. p_cnf->p_project, OXRES, OYRES, OXSTART, OYSTART, p_cnf->kam.near_plane,
  1278. p_cnf->kam.far_plane);
  1279. glDisable(GL_DEPTH_TEST);
  1280. oe_test_kriz_stred(p_cnf, 2.0f, d.x, d.y, d.z, POPIS_OS_ON, STRED_ON,
  1281. POSUN_VSE);
  1282. glEnable(GL_DEPTH_TEST);
  1283. /*
  1284. Kresli staticke svetla
  1285. */
  1286. if (p_cnf->cnf.svetla_kreslit) {
  1287. for (i = 0; i < MAX_EDIT_SVETEL; i++)
  1288. oe_kresli_staticke_svetlo(p_cnf, p_cnf->light + i, p_cnf->lightakt);
  1289. }
  1290. /*
  1291. Kresli dynamicky svetla
  1292. */
  1293. if (p_cnf->cnf.svetla_kreslit) {
  1294. for (i = 0; i < MAX_FLARE_SVETEL; i++)
  1295. oe_kresli_dynamicke_svetlo(p_cnf, p_cnf->p_dlight + i,
  1296. i == p_cnf->dl_akt);
  1297. }
  1298. /*
  1299. Kresli extra dynamicky svetla
  1300. */
  1301. if (p_cnf->cnf.svetla_kreslit) {
  1302. for (i = 0; i < MAX_FLARE_SVETEL; i++)
  1303. oe_kresli_extra_dynamicke_svetlo(p_cnf, p_cnf->p_edlight + i,
  1304. i == p_cnf->edl_akt);
  1305. }
  1306. /*
  1307. Renderuj Flare-efekty
  1308. */
  1309. if (!p_cnf->cnf.flare)
  1310. oe_kresli_edit_flare(p_cnf, p_cnf->flare, MAX_EDIT_SVETEL);
  1311. /*
  1312. Kresli kamery
  1313. */
  1314. if (p_cnf->cnf.kamera_kreslit) {
  1315. oe_kresli_kamery(p_cnf);
  1316. }
  1317. /*
  1318. Kresli stred levelu
  1319. */
  1320. if (p_cnf->elm.flag & ELIM_MAZAT)
  1321. oe_kresli_stred_levelu(p_cnf);
  1322. /*
  1323. Kresli seznam vybranych plosek
  1324. */
  1325. oe_kresli_group_face(p_cnf);
  1326. /*
  1327. Kresli 3d kostku podle mlznych kostek
  1328. */
  1329. if (p_cnf->cnf.mlhokostku_kreslit) {
  1330. oe_kresli_mlho_kostky(p_cnf);
  1331. }
  1332. /*
  1333. Kresli 3d kostku podle bounding-boxu kamery
  1334. */
  1335. if (p_cnf->cnf.kamera_kostka_kreslit) {
  1336. oe_kresli_bb_kamery(p_cnf);
  1337. }
  1338. /*
  1339. Mrizka pod levelem
  1340. */
  1341. if (p_cnf->cnf.grid && akt_editor == 1)
  1342. oe_kresli_grid(p_cnf);
  1343. /* Kresli-listu
  1344. */
  1345. if (p_cnf->lp.aktivni && akt_editor == GAME_EDITOR)
  1346. oe_kresli_listu_prvku(p_cnf);
  1347. /* Reset nastaveni (textury/barvy)
  1348. */
  1349. oe_renderuj_all_off();
  1350. }
  1351. void oe_renderuj_all_off(void)
  1352. {
  1353. text_init();
  1354. if (glstav_multitext_units > 3) {
  1355. text_set_num(3);
  1356. text_off(GL_TEXTURE_1D);
  1357. text_off(GL_TEXTURE_2D);
  1358. }
  1359. if (glstav_multitext_units > 2) {
  1360. text_set_num(2);
  1361. text_off(GL_TEXTURE_1D);
  1362. text_off(GL_TEXTURE_2D);
  1363. }
  1364. if (glstav_multitext_units > 1) {
  1365. text_set_num(1);
  1366. text_off(GL_TEXTURE_1D);
  1367. text_off(GL_TEXTURE_2D);
  1368. }
  1369. text_set_num(0);
  1370. text_off(GL_TEXTURE_1D);
  1371. text_off(GL_TEXTURE_2D);
  1372. blend_off();
  1373. specular_off();
  1374. reset_stage_bloky();
  1375. }
  1376. void oe_renderuj_scenu_pre(K_EDITOR * p_cnf)
  1377. {
  1378. if (!p_cnf->cnf.render || !karmin_aktivni)
  1379. return;
  1380. text_stage_func_nic(0);
  1381. reset_stage_bloky();
  1382. reset_kamera_flag();
  1383. glstav_zmena_kamery = TRUE;
  1384. /*
  1385. Animuje texturove animace
  1386. */
  1387. if (p_cnf->cnf.animace)
  1388. oe_animuj_materialy(p_cnf, FALSE);
  1389. /*
  1390. Animuje keyframy
  1391. */
  1392. if (ani_animuj_scenu(p_cnf))
  1393. doe_animace_updatuj(p_cnf);
  1394. /*
  1395. Animuje kosti
  1396. */
  1397. ani_animuj_kosti(p_cnf);
  1398. /*
  1399. Animuje texture materialy
  1400. */
  1401. if (ani_animuj_materialy(p_cnf))
  1402. doe_animace_updatuj_materialy(p_cnf);
  1403. /* Animuje kamery
  1404. */
  1405. if (ani_animuj_kamery(p_cnf))
  1406. doe_animace_updatuj_kamery(p_cnf);
  1407. /* Test mlho-kostek
  1408. */
  1409. oe_renderuj_mlho_kostky(p_cnf);
  1410. /* Mazani barvou
  1411. */
  1412. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  1413. if (p_cnf->zdcadlo_akt && p_cnf->cnf.render_zrcadla)
  1414. oe_renderuj_scenu_zrcadlo(p_cnf);
  1415. if (p_cnf->cnf.druh_sceny == SCENA_POLY && p_cnf->cnf.kdtree_render) {
  1416. oe_renderuj_scenu_kdtree(p_cnf, &p_cnf->kdtree);
  1417. }
  1418. else {
  1419. oe_renderuj_scenu_obyc(p_cnf, p_cnf->p_kont, p_cnf->max_kont);
  1420. }
  1421. /* Reset nastaveni
  1422. */
  1423. oe_renderuj_all_off();
  1424. }
  1425. void oe_renderuj_scenu_po(K_EDITOR * p_cnf)
  1426. {
  1427. if (!p_cnf->cnf.render || !karmin_aktivni)
  1428. return;
  1429. /* Vykresleni 3D systemove grafiky
  1430. */
  1431. oe_renderuj_scenu_system_3d(p_cnf);
  1432. /* Vykresleni 2D grafiky
  1433. */
  1434. oe_renderuj_scenu_system_2d(p_cnf);
  1435. /* Prehodi se buffery
  1436. */
  1437. flip();
  1438. doe_updatuj_konzoli_mys(p_cnf);
  1439. oe_updatuj_fps(p_cnf);
  1440. }
  1441. void oe_renderuj_scenu_editace(K_EDITOR * p_cnf,
  1442. EDIT_KONTEJNER * p_kont[KONT_NUM], int max_kont)
  1443. {
  1444. GLMATRIX *p_world;
  1445. dword x, y;
  1446. int akt, i;
  1447. float fx, fy, fz, z;
  1448. for (i = 0; i < max_kont; i++) {
  1449. if (!p_kont[i] || !p_kont[i]->kreslit)
  1450. continue;
  1451. // preskoc pro nekresleni sceny
  1452. if (!p_cnf->kreslit_scenu && p_kont[i]->prvek == K_CHYBA)
  1453. continue;
  1454. // preskoc pro nekresleni levelu
  1455. if (!p_cnf->kreslit_level && p_kont[i]->prvek != K_CHYBA)
  1456. continue;
  1457. if (p_kont[i]->kflag & KONT_ZRCADLO)
  1458. continue;
  1459. p_world = kont_world_matrix(p_kont[i]);
  1460. if (i == p_cnf->vybr_kont)
  1461. akt = p_cnf->vybr_objekt;
  1462. else
  1463. akt = K_CHYBA;
  1464. if (p_cnf->cnf.textury)
  1465. oe_kresli_kontejner(p_cnf, p_cnf->p_mat, p_kont[i], akt);
  1466. if (p_cnf->cnf.dratove)
  1467. oe_kresli_kontejner_dratove(p_cnf, p_cnf->p_mat, p_kont[i], akt);
  1468. /* Kresleni stredu kontejneru
  1469. if(p_cnf->cnf.objekt_stred) {
  1470. text_off();
  1471. if(i == p_cnf->vybr_kont)
  1472. oe_test_kriz_stred(p_cnf,VELIKOST_STREDU,0,0,0,POPIS_OS_ON,STRED_OFF,POSUN_VSE);
  1473. }
  1474. */
  1475. if (p_cnf->cnf.objekt_origin) {
  1476. if (transf_3d_2d(0, 0, 0, &x, &y, &z,
  1477. p_world, p_cnf->p_camera, p_cnf->p_project,
  1478. OXRES, OYRES, OXSTART, OYSTART,
  1479. p_cnf->kam.near_plane, p_cnf->kam.far_plane)) {
  1480. fx = fy = fz = 0;
  1481. transformuj_bod_matici(&fx, &fy, &fz, p_world);
  1482. }
  1483. }
  1484. }
  1485. }
  1486. /*
  1487. p_kam->flag &= ~(POSUN_OSA_X|POSUN_OSA_Y|POSUN_OSA_Z);
  1488. */
  1489. void oe_kresli_kamery(K_EDITOR * p_cnf)
  1490. {
  1491. KAMERA *p_kam;
  1492. int i;
  1493. for (i = 0; i < MAX_EDIT_KAMER; i++) {
  1494. p_kam = p_cnf->kamery + i;
  1495. if (p_kam->cislo != K_CHYBA) {
  1496. set_matrix_world(&p_cnf->init_matrix);
  1497. oe_kresli_kameru(p_kam, !p_cnf->cnf.kamera_aktivni
  1498. && p_cnf->kamakt == i);
  1499. if (POSUN_TARGET & p_kam->flag)
  1500. oe_kresli_editacni_stred(p_cnf, &p_kam->t, p_kam->flag);
  1501. if (POSUN_POZICI & p_kam->flag)
  1502. oe_kresli_editacni_stred(p_cnf, &p_kam->p, p_kam->flag);
  1503. }
  1504. }
  1505. }
  1506. /* Rendering prez obalky
  1507. */
  1508. void oe_renderuj_scenu_kdtree_rec(K_EDITOR * p_cnf, KD_BUNKA * p_prvni,
  1509. GLMATRIX * p_m, int kreslit)
  1510. {
  1511. EDIT_MESH_POLY *p_poly;
  1512. EDIT_KONTEJNER *p_kont;
  1513. int i;
  1514. if (p_cnf->cnf.kdtree_bunka == p_prvni->cislo || kreslit) {
  1515. text_set(0, GL_TEXTURE_2D);
  1516. kresli_oktanovou_bunku_minmax(&p_prvni->min, &p_prvni->max, 0xffffffff);
  1517. kreslit = TRUE;
  1518. }
  1519. if (p_cnf->cnf.kdtree_bunka == p_prvni->cislo
  1520. || p_cnf->cnf.kdtree_kreslit_vse || kreslit) {
  1521. for (i = 0; i < p_prvni->polozek; i++) {
  1522. if (p_prvni->p_polozka_typ[i] == KD_POLY) {
  1523. p_poly = p_prvni->p_polozka[i];
  1524. if (p_poly->p_lightnum)
  1525. oe_kresli_poly_3d_game(p_poly, p_cnf->p_mat, p_cnf->cnf.light_maps);
  1526. else
  1527. oe_kresli_poly_3d(p_poly, p_cnf->p_mat);
  1528. }
  1529. else {
  1530. p_kont = p_prvni->p_polozka[i];
  1531. oe_kresli_kontejner(p_cnf, p_cnf->p_mat, p_kont, -1);
  1532. }
  1533. }
  1534. }
  1535. if (p_prvni->p_next) {
  1536. oe_renderuj_scenu_kdtree_rec(p_cnf, p_prvni->p_next, p_m, kreslit);
  1537. oe_renderuj_scenu_kdtree_rec(p_cnf, p_prvni->p_next + 1, p_m, kreslit);
  1538. }
  1539. }
  1540. int viditelnych = 0;
  1541. int polygonu = 0;
  1542. int facu = 0;
  1543. void oe_renderuj_scenu_kdtree(K_EDITOR * p_cnf, KD_BUNKA * p_prvni)
  1544. {
  1545. GLMATRIX m;
  1546. /*
  1547. Nulova transformace
  1548. */
  1549. if (p_cnf->polynum) {
  1550. blend_off();
  1551. text_set_num(0);
  1552. glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
  1553. text_on(GL_TEXTURE_2D);
  1554. text_set_num(1);
  1555. text_on(GL_TEXTURE_2D);
  1556. glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  1557. viditelnych = 0;
  1558. polygonu = 0;
  1559. facu = 0;
  1560. calc_3d_2d_matrix(&p_cnf->init_matrix, p_cnf->p_camera, p_cnf->p_project,
  1561. &m);
  1562. set_matrix_world(&p_cnf->init_matrix);
  1563. if (kd_visibility(&p_prvni->min, &p_prvni->max, &m)) {
  1564. oe_renderuj_scenu_kdtree_rec(p_cnf, p_prvni, &m, FALSE);
  1565. }
  1566. }
  1567. }
  1568. // Ve hre skusit mazat akorat Z-buffer !!!
  1569. void oe_renderuj_scenu_obyc(K_EDITOR * p_cnf,
  1570. EDIT_KONTEJNER * p_kont[KONT_NUM], int max_kont)
  1571. {
  1572. int i;
  1573. /*
  1574. Kresleni levelu/sceny
  1575. */
  1576. oe_renderuj_scenu_editace(p_cnf, p_kont, max_kont);
  1577. /*
  1578. Kresli berusci level
  1579. */
  1580. if (p_cnf->kreslit_level)
  1581. be_renderuj_scenu(p_cnf);
  1582. /*
  1583. Nulova transformace
  1584. */
  1585. set_matrix_world(&p_cnf->init_matrix);
  1586. /*
  1587. Kresli seznamy polygonu
  1588. */
  1589. if (p_cnf->polynum) {
  1590. text_set_num(1);
  1591. text_on(GL_TEXTURE_2D);
  1592. glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  1593. for (i = 0; i < p_cnf->polynum; i++) {
  1594. if (p_cnf->p_poly[i].kreslit
  1595. && !(p_cnf->p_poly[i].kflag & KONT_ZRCADLO)) {
  1596. if (p_cnf->p_poly[i].p_lightnum)
  1597. oe_kresli_poly_3d_game(p_cnf->p_poly + i, p_cnf->p_mat,
  1598. p_cnf->cnf.light_maps);
  1599. else
  1600. oe_kresli_poly_3d(p_cnf->p_poly + i, p_cnf->p_mat);
  1601. }
  1602. }
  1603. }
  1604. /*
  1605. Renderuj Flare-efekty
  1606. */
  1607. if (p_cnf->cnf.flare)
  1608. oe_kresli_game_flare(p_cnf, p_cnf->flare, MAX_EDIT_SVETEL);
  1609. }
  1610. void oe_renderuj_scenu_zrcadlo(K_EDITOR * p_cnf)
  1611. {
  1612. ZDRCADLO_DESC_POLY *p_poly;
  1613. EDIT_KONTEJNER **p_kont = p_cnf->p_kont;
  1614. int i, max_kont = p_cnf->max_kont;
  1615. int k, o;
  1616. if (p_cnf->cnf.render_zrcadla) {
  1617. p_cnf->mod_matrix_akt = TRUE;
  1618. p_cnf->mod_matrix = p_cnf->zrcadlo.ref;
  1619. oe_calc_clip_focus(p_cnf);
  1620. assert(GL_MAX_CLIP_PLANES >= 4);
  1621. glEnable(GL_CLIP_PLANE0);
  1622. glEnable(GL_CLIP_PLANE1);
  1623. glEnable(GL_CLIP_PLANE2);
  1624. glEnable(GL_CLIP_PLANE3);
  1625. glEnable(GL_CLIP_PLANE4);
  1626. glClipPlane(GL_CLIP_PLANE0, (double *) p_cnf->zrcadlo.r);
  1627. glClipPlane(GL_CLIP_PLANE1, (double *) (p_cnf->zrcadlo.r + 1));
  1628. glClipPlane(GL_CLIP_PLANE2, (double *) (p_cnf->zrcadlo.r + 2));
  1629. glClipPlane(GL_CLIP_PLANE3, (double *) (p_cnf->zrcadlo.r + 3));
  1630. glClipPlane(GL_CLIP_PLANE4, (double *) (p_cnf->zrcadlo.r + 4));
  1631. cull_prehod();
  1632. // Ma se kreslit berusci level ?
  1633. if (p_cnf->kreslit_level)
  1634. be_renderuj_scenu(p_cnf);
  1635. // Ma se kreslit scena ?
  1636. if (p_cnf->kreslit_scenu) {
  1637. for (i = 0; i < max_kont; i++) {
  1638. if (p_kont[i] &&
  1639. p_kont[i]->kreslit &&
  1640. p_cnf->cnf.textury && !(p_kont[i]->kflag & KONT_ZRCADLO))
  1641. oe_kresli_kontejner(p_cnf, p_cnf->p_mat, p_kont[i], K_CHYBA);
  1642. }
  1643. set_matrix_world(&p_cnf->mod_matrix);
  1644. for (i = 0; i < p_cnf->polynum; i++) {
  1645. if (p_cnf->p_poly[i].kreslit
  1646. && !(p_cnf->p_poly[i].kflag & KONT_ZRCADLO))
  1647. if (p_cnf->p_poly[i].p_lightnum)
  1648. oe_kresli_poly_3d_game(p_cnf->p_poly + i, p_cnf->p_mat,
  1649. p_cnf->cnf.light_maps);
  1650. else
  1651. oe_kresli_poly_3d(p_cnf->p_poly + i, p_cnf->p_mat);
  1652. }
  1653. if (p_cnf->cnf.flare)
  1654. oe_kresli_game_flare(p_cnf, p_cnf->flare, MAX_EDIT_SVETEL);
  1655. }
  1656. cull_prehod();
  1657. glDisable(GL_CLIP_PLANE0);
  1658. glDisable(GL_CLIP_PLANE1);
  1659. glDisable(GL_CLIP_PLANE2);
  1660. glDisable(GL_CLIP_PLANE3);
  1661. glDisable(GL_CLIP_PLANE4);
  1662. p_cnf->mod_matrix_akt = FALSE;
  1663. }
  1664. p_poly = p_cnf->zrcadlo.p_poly;
  1665. while (p_poly) {
  1666. k = p_poly->zrcadlo_k;
  1667. o = p_poly->zrcadlo_o;
  1668. if (p_cnf->p_kont[k] && p_cnf->p_kont[k]->p_obj[o]) {
  1669. set_matrix_world(kont_world_matrix(p_cnf->p_kont[k]));
  1670. oe_kresli_objekt(p_cnf, p_cnf->p_kont[k],
  1671. p_cnf->p_kont[k]->p_obj[o], p_cnf->p_mat, FALSE, FALSE);
  1672. }
  1673. else {
  1674. if (p_poly->poly != K_CHYBA && p_poly->poly < p_cnf->polynum) {
  1675. set_matrix_world_init();
  1676. if (p_cnf->p_poly[p_poly->poly].p_lightnum)
  1677. oe_kresli_poly_3d_game(p_cnf->p_poly + p_poly->poly,
  1678. p_cnf->p_mat, p_cnf->cnf.light_maps);
  1679. else
  1680. oe_kresli_poly_3d(p_cnf->p_poly + p_poly->poly, p_cnf->p_mat);
  1681. }
  1682. }
  1683. p_poly = p_poly->p_next;
  1684. }
  1685. }
  1686. //p_kam->flag &= ~(POSUN_OSA_X|POSUN_OSA_Y|POSUN_OSA_Z);
  1687. int oe_test_kriz_stred(K_EDITOR * p_cnf, float vzdal, float x_s, float y_s,
  1688. float z_s, int popis, int stred, int akt_osa)
  1689. {
  1690. GLMATRIX inv, rr;
  1691. dword barva;
  1692. int x, y;
  1693. float z;
  1694. BOD p;
  1695. oe_renderuj_all_off();
  1696. if (stred)
  1697. push_matrix_world(init_matrix(&inv));
  1698. else {
  1699. get_matrix_world(&inv);
  1700. }
  1701. p.x = x_s;
  1702. p.y = y_s;
  1703. p.z = z_s;
  1704. calc_3d_2d_matrix(&inv, p_cnf->p_camera, p_cnf->p_project, &rr);
  1705. transformuj_bod_matici(&p.x, &p.y, &p.z, &rr);
  1706. vzdal = vzdal * p.z * 0.1f;
  1707. if (popis) {
  1708. set_matrix_2d(OXRES, OYRES);
  1709. if (transf_3d_2d_matrix(vzdal + x_s, y_s, z_s, &x, &y, &z, &rr,
  1710. OXRES, OYRES, OXSTART, OYSTART,
  1711. p_cnf->kam.near_plane, p_cnf->kam.far_plane))
  1712. ddw_surf_xy(x, y, "X");
  1713. if (transf_3d_2d_matrix(x_s, vzdal + y_s, z_s, &x, &y, &z, &rr,
  1714. OXRES, OYRES, OXSTART, OYSTART,
  1715. p_cnf->kam.near_plane, p_cnf->kam.far_plane))
  1716. ddw_surf_xy(x, y, "Y");
  1717. if (transf_3d_2d_matrix(x_s, y_s, vzdal + z_s, &x, &y, &z, &rr,
  1718. OXRES, OYRES, OXSTART, OYSTART,
  1719. p_cnf->kam.near_plane, p_cnf->kam.far_plane))
  1720. ddw_surf_xy(x, y, "Z");
  1721. ret_matrix_2d();
  1722. }
  1723. glBegin(GL_LINES);
  1724. barva = (akt_osa & POSUN_OSA_X) ? DDRGB(1, 0, 0) : DDRGB(0, 0, 0);
  1725. glColor3ubv((byte *) & barva);
  1726. glVertex3f(x_s, y_s, z_s);
  1727. glVertex3f(vzdal + x_s, y_s, z_s);
  1728. barva = (akt_osa & POSUN_OSA_Y) ? DDRGB(0, 0, 1) : DDRGB(0, 0, 0);
  1729. glColor3ubv((byte *) & barva);
  1730. glVertex3f(x_s, y_s, z_s);
  1731. glVertex3f(x_s, vzdal + y_s, z_s);
  1732. barva = (akt_osa & POSUN_OSA_Z) ? DDRGB(0, 1, 0) : DDRGB(0, 0, 0);
  1733. glColor3ubv((byte *) & barva);
  1734. glVertex3f(x_s, y_s, z_s);
  1735. glVertex3f(x_s, y_s, vzdal + z_s);
  1736. glEnd();
  1737. if (stred)
  1738. pop_matrix_world();
  1739. return (TRUE);
  1740. }
  1741. int oe_test_kriz_stred_bod(K_EDITOR * p_cnf, float vzdal, BOD * p_bod,
  1742. int popis, int stred, int akt_osa)
  1743. {
  1744. return (oe_test_kriz_stred(p_cnf, vzdal, p_bod->x, p_bod->y, p_bod->z,
  1745. popis, stred, akt_osa));
  1746. }
  1747. // renderovat 2D nebo 3D poly ?
  1748. /*
  1749. typedef struct _POZICE_BODU {
  1750. D3DVALUE x,y,z; // 3D body
  1751. D3DVALUE nx,ny,nz; // normalove vektory
  1752. DWORD diff; // diffuse color
  1753. D3DVALUE tx,ty,tz,tw; // transformovane souradnice
  1754. dword transf; // flag transformace
  1755. } POZICE_BODU;
  1756. typedef struct _POZICE_BODU_2D {
  1757. D3DVALUE x,y,z,w; // transformovane souradnice
  1758. DWORD diff; // diffuse color
  1759. dword transf; // flag transformace
  1760. } POZICE_BODU_2D;
  1761. typedef struct _TEXT_KOORD {
  1762. D3DVALUE tu1,tv1;
  1763. D3DVALUE tu2,tv2;
  1764. POZICE_BODU *p_bod;
  1765. } TEXT_KOORD;
  1766. typedef struct _EDIT_MESH_POLY { //celej kontejner
  1767. POZICE_BODU *p_pozice; // list bodu
  1768. TEXT_KOORD *p_koord; // list texture koordinatu - plosky po 3
  1769. dword flag; // flag meshu -> stejne jako u kontejneru
  1770. dword facenum; // co face to objekt -> kazdy face ma svuj material
  1771. dword matnum; // pocet materialu
  1772. word *p_pocty; // pocty plosek
  1773. dword *p_mat; // pole pointeru na materialy na jednotlive objekty
  1774. } EDIT_MESH_POLY;
  1775. Renderovaci postup:
  1776. 1. transformace vsech bodu (pokud nejsou)
  1777. 2. kopie vsech bodu do listu (vertex-casch)
  1778. 3. render z casch
  1779. */
  1780. void oe_kresli_poly_3d(EDIT_MESH_POLY * p_poly, EDIT_MATERIAL ** p_mat)
  1781. {
  1782. int i;
  1783. oe_nastav_material_single_poly(p_cnf->p_smat ? *(p_cnf->p_smat) : NULL,
  1784. p_mat[p_poly->material], p_poly);
  1785. text_off(GL_TEXTURE_1D);
  1786. text_off(GL_TEXTURE_2D);
  1787. glBegin(GL_TRIANGLES);
  1788. for (i = 0; i < p_poly->facenum; i++) {
  1789. glTexCoord2fv(&p_poly->p_koord[i].tu1);
  1790. glColor4fv(&p_poly->p_koord[i].dr);
  1791. glSecondaryColor3fvEXT(&p_poly->p_koord[i].sr);
  1792. glNormal3fv(&p_poly->p_koord[i].nx);
  1793. glVertex3fv(&p_poly->p_koord[i].x);
  1794. }
  1795. glEnd();
  1796. }
  1797. void oe_kresli_poly_3d_game(EDIT_MESH_POLY * p_poly, EDIT_MATERIAL ** p_mat,
  1798. int light)
  1799. {
  1800. // pozice bodu k 3D renderingu
  1801. int i, l, last, textur, *p_int, ind;
  1802. last = 0;
  1803. if (!light) {
  1804. textur =
  1805. oe_nastav_material_single_poly(p_cnf->p_smat ? *(p_cnf->p_smat) : NULL,
  1806. p_mat[p_poly->material], p_poly);
  1807. text_on(GL_TEXTURE_2D);
  1808. }
  1809. else {
  1810. text_set_num(1);
  1811. text_off(GL_TEXTURE_1D);
  1812. text_off(GL_TEXTURE_2D);
  1813. text_set_num(0);
  1814. text_on(GL_TEXTURE_2D);
  1815. }
  1816. for (l = 0; l < p_poly->lightnum; l++) {
  1817. if (p_poly->p_light[l]) {
  1818. text_set(p_poly->p_light[l]->text, p_poly->p_light[l]->typ);
  1819. }
  1820. glBegin(GL_TRIANGLES);
  1821. for (i = 0; i < p_poly->p_lightnum[l]; i++) {
  1822. if (!light) {
  1823. p_int = glstav_text_map_indicie;
  1824. if ((ind = *p_int) != K_CHYBA)
  1825. glMultiTexCoord2fvARB(GL_TEXTURE0_ARB,
  1826. ((float *) (&p_poly->p_koord[last + i].tu1)) + ((ind) << 1));
  1827. p_int++;
  1828. if ((ind = *p_int) != K_CHYBA)
  1829. glMultiTexCoord2fvARB(GL_TEXTURE1_ARB,
  1830. ((float *) (&p_poly->p_koord[last + i].tu1)) + ((ind) << 1));
  1831. p_int++;
  1832. if ((ind = *p_int) != K_CHYBA)
  1833. glMultiTexCoord2fvARB(GL_TEXTURE2_ARB,
  1834. ((float *) (&p_poly->p_koord[last + i].tu1)) + ((ind) << 1));
  1835. p_int++;
  1836. if ((ind = *p_int) != K_CHYBA)
  1837. glMultiTexCoord2fvARB(GL_TEXTURE3_ARB,
  1838. ((float *) (&p_poly->p_koord[last + i].tu1)) + ((ind) << 1));
  1839. glMultiTexCoord2fvARB(GL_TEXTURE0_ARB + glstav_text_poly_indicie,
  1840. &p_poly->p_koord[last + i].tul);
  1841. }
  1842. else {
  1843. glMultiTexCoord2fvARB(GL_TEXTURE0_ARB,
  1844. &p_poly->p_koord[last + i].tul);
  1845. }
  1846. glColor4fv(&p_poly->p_koord[last + i].dr);
  1847. glSecondaryColor3fvEXT(&p_poly->p_koord[last + i].sr);
  1848. glNormal3fv(&p_poly->p_koord[last + i].nx);
  1849. glVertex3fv(&p_poly->p_koord[last + i].x);
  1850. }
  1851. glEnd();
  1852. last += p_poly->p_lightnum[l];
  1853. }
  1854. }
  1855. void oe_kresli_editacni_stred(K_EDITOR * p_cnf, BOD * p_stred, int flag)
  1856. {
  1857. text_off(GL_TEXTURE_1D);
  1858. text_off(GL_TEXTURE_2D);
  1859. glDisable(GL_DEPTH_TEST);
  1860. oe_test_kriz_stred(p_cnf, VELIKOST_STREDU, p_stred->x, p_stred->y,
  1861. p_stred->z, POPIS_OS_ON, STRED_ON, flag);
  1862. glEnable(GL_DEPTH_TEST);
  1863. }
  1864. void oe_kresli_listu_prvku(K_EDITOR * p_cnf)
  1865. {
  1866. LISTA_PRVKU *p_lista = &p_cnf->lp;
  1867. B_KONFIG *p_bnf = &p_cnf->bnf;
  1868. GLMATRIX cam, inv, prj;
  1869. BOD p = { -0.6f, 0, 0.6f };
  1870. float barvy[4], nr;
  1871. int i, k, oken;
  1872. int x, y, dx, dy;
  1873. rgb_float(p_cnf->barva_pozadi, barvy);
  1874. x = 0;
  1875. y = p_cnf->wyres - LISTA_X;
  1876. dx = LISTA_X;
  1877. dy = LISTA_X;
  1878. oken = p_cnf->lp.oken;
  1879. nr = 1.0f;
  1880. projection_matrix(&prj, DEG2RAD(30.0f), (float) dx / (float) dy, nr,
  1881. 100.0f);
  1882. set_matrix_project_push(&prj);
  1883. calc_camera_bod(&cam, &inv, &p, 6.5f, DEG2RAD(45.0f), DEG2RAD(45.0f));
  1884. get_matrix_camera(&inv);
  1885. set_matrix_camera(&cam);
  1886. glEnable(GL_SCISSOR_TEST);
  1887. glViewport(x, y, p_cnf->wxres, dy);
  1888. glScissor(x, y, p_cnf->wxres, dy);
  1889. glClearColor(0.4f, 0.4f, 0.4f, 1.0f);
  1890. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  1891. glClearColor(0.5f, 0.5f, 1.0f, 1.0f);
  1892. for (i = 0; i < oken; i++) {
  1893. k = i + p_lista->prvni;
  1894. if (k < p_lista->prvnum) {
  1895. k = p_lista->p_prv[k];
  1896. glViewport(x, y, dx, dy);
  1897. glScissor(x, y, dx, dy);
  1898. if (i == p_lista->prvakt)
  1899. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  1900. if (k != K_CHYBA && p_bnf->p_prv_dat[k]) {
  1901. oe_kresli_kontejner(p_cnf, p_cnf->bnf.p_mat,
  1902. p_bnf->p_prv_dat[k]->p_kont, K_CHYBA);
  1903. }
  1904. x += LISTA_X;
  1905. }
  1906. }
  1907. glClearColor(barvy[0], barvy[1], barvy[2], 1.0f);
  1908. glDisable(GL_SCISSOR_TEST);
  1909. glViewport(p_cnf->wx, p_cnf->wy, p_cnf->wxres, p_cnf->wyres);
  1910. set_matrix_project_pop();
  1911. set_matrix_camera(&inv);
  1912. }