3dinterface.h 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165
  1. /*
  2. 3D interface
  3. */
  4. #ifndef __3D_INTERFACE_H__
  5. #define __3D_INTERFACE_H__
  6. /*
  7. Stavovy stroj
  8. */
  9. extern int glstav_blending; // blending on-off
  10. extern int glstav_cull; // cull mod
  11. extern int glstav_cull_mod; // jaka strana se orezava
  12. extern int glstav_lighting; // gl svetla
  13. extern int glstav_specular; // spekularni svetla
  14. extern int glstav_diffuse; // diffusni svetla
  15. extern int glstav_mlha;
  16. extern int glstav_mlha_causal;
  17. extern int glstav_array_diffuse;
  18. extern int glstav_array_specular;
  19. extern int glstav_array_normal;
  20. extern int glstav_genenv_s[6]; // 1
  21. extern int glstav_genenv_t[6]; // 2
  22. extern int glstav_genenv_r[6]; // 3
  23. extern int glstav_genenv_q[6]; // 4
  24. extern int glstav_multitext_units;
  25. extern int glstav_alfa_blok;
  26. extern int glstav_alfa_test;
  27. extern int glstav_text_blok[6];
  28. extern int glstav_cliping;
  29. extern int glstav_pn_triangles;
  30. extern int glstav_deph_test;
  31. extern int glstav_zmask;
  32. extern int glstav_bump_mapping;
  33. extern int glstav_zmena_kamery;
  34. extern int glstav_text_akt; // aktivni texury
  35. extern int glstav_text_akt_client; // aktivni klientska texura
  36. extern int glstav_textury_1d[6]; // textury
  37. extern int glstav_textury_2d[6]; // textury
  38. extern GLuint glstav_last_text_1d[6]; // posledni textura
  39. extern GLuint glstav_last_text_2d[6]; // posledni textura
  40. extern int glstav_text_array[6]; // texturovaci pole
  41. extern int glstav_text_array_akt; // aktualni texturovaci pole
  42. extern int glstav_text_map_indicie[6]; // mapovaci indicie pro textury (cislo mapy, cislo stavu)
  43. extern int glstav_text_poly_indicie; // mapovaci indicie pro poly (cislo mapy)
  44. extern unsigned int glstav_posun_flagy2[6];
  45. extern unsigned int glstav_texgen_on[6];
  46. extern unsigned int glstav_texgen_eye_lin_flagy[6];
  47. extern unsigned int glstav_texgen_sphere_flagy[6];
  48. extern GLMATRIX glstav_texgen[6];
  49. extern int glstav_view_x;
  50. extern int glstav_view_y;
  51. extern int glstav_view_dx;
  52. extern int glstav_view_dy;
  53. extern int glstav_matrix_2d_mod;
  54. //#define STATE_BLOK_PRUHL 50 // zpruhlednovaci state blok
  55. #define STATE_BLOK_PRUHL 50
  56. #define STAGE_ALFA_FUNKCI 5
  57. #define STAGE_TEXT_FUNKCI 9
  58. extern STAGE_FUNC_ALFA p_alfa_stage_func[STAGE_ALFA_FUNKCI];
  59. extern STAGE_FUNC p_text_stage_func[STAGE_TEXT_FUNKCI];
  60. extern STAGE_FUNC_ELEM p_text_stage_func_elem[STAGE_TEXT_FUNKCI];
  61. extern EDIT_STATE_ALFA_BLOK alfa_stage_edit_blok[STAGE_ALFA_FUNKCI + STATE_BLOK_PRUHL + 1];
  62. extern EDIT_STATE_TEXT_BLOK text_stage_edit_blok[STAGE_TEXT_FUNKCI];
  63. #define STAGE_ALFA_MASKA 4
  64. #define BLOK_MODULACE 0
  65. #define BLOK_ADD 1
  66. #define BLOK_DECAL 2
  67. #define BLOK_BLEND 3
  68. #define BLOK_REPLACE 4
  69. #define BLOK_DOT3_BUMP 5
  70. #define BLOK_MODULACE2X 6
  71. #define BLOK_BUMP_ENV 7
  72. /* Define pro stage_funkce
  73. */
  74. #define DOT3_BUMP 0
  75. #define DOT3_TEXT 1
  76. #define DOT3_ENV 2
  77. #define DUDV_BUMP 0 // normalova mapa
  78. #define DUDV_ENV 1 // Environment-mapa
  79. #define DUDV_TEXT 2 // zakladni textura
  80. /* Automaticky nahrazovani
  81. */
  82. #define AUTO_BUMP_DOT3 5 // dot3 color blok
  83. #define AUTO_BUMP_DOT3ENV 6 // dot3 env blok
  84. void nahod_state_bloky(void);
  85. #define MAX_WORD_MATRIX_STACK 32
  86. extern GLMATRIX __mat_kamera;
  87. extern GLMATRIX __mat_world;
  88. extern GLMATRIX __mat_vysl;
  89. extern GLMATRIX __mat_camera_project; // transformuje 3D do 2D
  90. extern GLMATRIX __mat_init;
  91. extern GLMATRIX __mat_top_matrix[MAX_WORD_MATRIX_STACK]; // druha word-matrix -> top-matrix
  92. extern int __mat_top_matrix_akt;
  93. extern GLMATRIX __mat_tmp;
  94. extern int __mat_text[4];
  95. #define TEXGEN_NIC 0
  96. #define TEXGEN_SPHEREMAP 1
  97. #define TEXGEN_EYE_LINEAR 2
  98. void glstav_reset(void);
  99. // matmult top_matrix*wordl*camera*project
  100. /* Low-level matice
  101. */
  102. inline GLMATRIX *set_matrix_texture(int num, GLMATRIX * p_text)
  103. {
  104. glMatrixMode(GL_TEXTURE);
  105. glLoadMatrixf((float *) p_text);
  106. __mat_text[num] = TRUE;
  107. return (p_text);
  108. }
  109. inline void ret_matrix_texture(int num)
  110. {
  111. if (__mat_text[num]) {
  112. glMatrixMode(GL_TEXTURE);
  113. glLoadIdentity();
  114. __mat_text[num] = FALSE;
  115. }
  116. }
  117. inline GLMATRIX *get_matrix_world_camera(void)
  118. {
  119. return (&__mat_vysl);
  120. }
  121. inline GLMATRIX *set_matrix_world_top(GLMATRIX * p_top_world)
  122. {
  123. if (__mat_top_matrix_akt + 1 < MAX_WORD_MATRIX_STACK) {
  124. if (!__mat_top_matrix_akt) {
  125. __mat_top_matrix[0] = *p_top_world;
  126. }
  127. else {
  128. mat_mult_dir(__mat_top_matrix + __mat_top_matrix_akt - 1, p_top_world,
  129. __mat_top_matrix + __mat_top_matrix_akt);
  130. }
  131. mat_mult_dir(&__mat_world, __mat_top_matrix + __mat_top_matrix_akt,
  132. &__mat_tmp);
  133. mat_mult_dir(&__mat_tmp, &__mat_kamera, &__mat_vysl);
  134. glMatrixMode(GL_MODELVIEW);
  135. glLoadMatrixf((float *) &__mat_vysl);
  136. __mat_top_matrix_akt++;
  137. return (p_top_world);
  138. }
  139. else {
  140. return (NULL);
  141. }
  142. }
  143. inline void ret_matrix_world_top(void)
  144. {
  145. if (__mat_top_matrix_akt > 0) {
  146. __mat_top_matrix_akt--;
  147. if (__mat_top_matrix_akt) {
  148. mat_mult_dir(&__mat_world, __mat_top_matrix + __mat_top_matrix_akt - 1,
  149. &__mat_tmp);
  150. mat_mult_dir(&__mat_tmp, &__mat_kamera, &__mat_vysl);
  151. }
  152. else {
  153. mat_mult_dir(&__mat_world, &__mat_kamera, &__mat_vysl);
  154. }
  155. glMatrixMode(GL_MODELVIEW);
  156. glLoadMatrixf((float *) &__mat_vysl);
  157. }
  158. }
  159. inline GLMATRIX *set_matrix_camera(GLMATRIX * p_cam)
  160. {
  161. memcpy(&__mat_kamera, p_cam, sizeof(GLMATRIX));
  162. if (__mat_top_matrix_akt) {
  163. mat_mult_dir(&__mat_world, __mat_top_matrix + __mat_top_matrix_akt - 1,
  164. &__mat_tmp);
  165. mat_mult_dir(&__mat_tmp, &__mat_kamera, &__mat_vysl);
  166. }
  167. else {
  168. mat_mult_dir(&__mat_world, &__mat_kamera, &__mat_vysl);
  169. }
  170. glMatrixMode(GL_MODELVIEW);
  171. glLoadMatrixf((float *) &__mat_vysl);
  172. glstav_zmena_kamery = TRUE;
  173. return (p_cam);
  174. }
  175. inline GLMATRIX *get_matrix_camera(GLMATRIX * p_cam)
  176. {
  177. memcpy(p_cam, &__mat_kamera, sizeof(GLMATRIX));
  178. return (p_cam);
  179. }
  180. inline GLMATRIX *get_matrix_camera_point(void)
  181. {
  182. return (&__mat_kamera);
  183. }
  184. inline GLMATRIX *set_matrix_world(GLMATRIX * p_world)
  185. {
  186. memcpy(&__mat_world, p_world, sizeof(GLMATRIX));
  187. if (__mat_top_matrix_akt) {
  188. mat_mult_dir(&__mat_world, __mat_top_matrix + __mat_top_matrix_akt - 1,
  189. &__mat_tmp);
  190. mat_mult_dir(&__mat_tmp, &__mat_kamera, &__mat_vysl);
  191. }
  192. else {
  193. mat_mult_dir(&__mat_world, &__mat_kamera, &__mat_vysl);
  194. }
  195. glMatrixMode(GL_MODELVIEW);
  196. glLoadMatrixf((float *) &__mat_vysl);
  197. return (p_world);
  198. }
  199. inline void set_matrix_world_init(void)
  200. {
  201. memcpy(&__mat_world, &__mat_init, sizeof(GLMATRIX));
  202. if (__mat_top_matrix_akt) {
  203. mat_mult_dir(&__mat_world, __mat_top_matrix + __mat_top_matrix_akt - 1,
  204. &__mat_tmp);
  205. mat_mult_dir(&__mat_tmp, &__mat_kamera, &__mat_vysl);
  206. }
  207. else {
  208. mat_mult_dir(&__mat_world, &__mat_kamera, &__mat_vysl);
  209. }
  210. glMatrixMode(GL_MODELVIEW);
  211. glLoadMatrixf((float *) &__mat_vysl);
  212. }
  213. inline GLMATRIX *get_matrix_world(GLMATRIX * p_world)
  214. {
  215. memcpy(p_world, &__mat_world, sizeof(GLMATRIX));
  216. return (p_world);
  217. }
  218. inline GLMATRIX *push_matrix_world(GLMATRIX * p_world)
  219. {
  220. GLMATRIX tmp1;
  221. glMatrixMode(GL_MODELVIEW);
  222. glPushMatrix();
  223. if (__mat_top_matrix_akt) {
  224. mat_mult_dir(p_world, __mat_top_matrix + __mat_top_matrix_akt - 1,
  225. &__mat_tmp);
  226. mat_mult_dir(&__mat_tmp, &__mat_kamera, &__mat_vysl);
  227. }
  228. else {
  229. mat_mult_dir(p_world, &__mat_kamera, &tmp1);
  230. }
  231. glLoadMatrixf((float *) &tmp1);
  232. return (p_world);
  233. }
  234. inline void pop_matrix_world(void)
  235. {
  236. glMatrixMode(GL_MODELVIEW);
  237. glPopMatrix();
  238. }
  239. inline void set_matrix_all(GLMATRIX * p_cam, GLMATRIX * p_world)
  240. {
  241. memcpy(&__mat_kamera, p_cam, sizeof(GLMATRIX));
  242. memcpy(&__mat_world, p_world, sizeof(GLMATRIX));
  243. if (__mat_top_matrix_akt) {
  244. mat_mult_dir(&__mat_world, __mat_top_matrix + __mat_top_matrix_akt - 1,
  245. &__mat_tmp);
  246. mat_mult_dir(&__mat_tmp, &__mat_kamera, &__mat_vysl);
  247. }
  248. else {
  249. mat_mult_dir(&__mat_world, &__mat_kamera, &__mat_vysl);
  250. }
  251. glMatrixMode(GL_MODELVIEW);
  252. glLoadMatrixf((float *) &__mat_vysl);
  253. glstav_zmena_kamery = TRUE;
  254. }
  255. inline GLMATRIX *set_matrix_project(GLMATRIX * p_project)
  256. {
  257. glMatrixMode(GL_PROJECTION);
  258. glLoadMatrixf((float *) p_project);
  259. return (p_project);
  260. }
  261. inline GLMATRIX *get_matrix_project(GLMATRIX * p_project)
  262. {
  263. return (p_project);
  264. }
  265. inline GLMATRIX *set_matrix_project_push(GLMATRIX * p_project)
  266. {
  267. glMatrixMode(GL_PROJECTION);
  268. glPushMatrix();
  269. glLoadMatrixf((float *) p_project);
  270. return (p_project);
  271. }
  272. inline void set_matrix_project_pop(void)
  273. {
  274. glMatrixMode(GL_PROJECTION);
  275. glPopMatrix();
  276. }
  277. inline void set_matrix_view(int x, int y, int max_x, int max_y)
  278. {
  279. glstav_view_x = x;
  280. glstav_view_y = y;
  281. glstav_view_dx = max_x;
  282. glstav_view_dy = max_y;
  283. glViewport(x, y, max_x, max_y);
  284. }
  285. inline void get_matrix_view(int *p_x, int *p_y, int *p_max_x, int *p_max_y)
  286. {
  287. *p_x = glstav_view_x;
  288. *p_y = glstav_view_y;
  289. *p_max_x = glstav_view_dx;
  290. *p_max_y = glstav_view_dy;
  291. }
  292. inline void set_matrix_2d(int xres, int yres)
  293. {
  294. if (!glstav_matrix_2d_mod) {
  295. glstav_matrix_2d_mod = TRUE;
  296. glMatrixMode(GL_MODELVIEW);
  297. glPushMatrix();
  298. glLoadIdentity();
  299. glMatrixMode(GL_PROJECTION);
  300. glPushMatrix();
  301. glLoadIdentity();
  302. glOrtho(0.0f, xres, yres, 0.0f, 0.0f, 1.0f);
  303. }
  304. }
  305. inline void ret_matrix_2d(void)
  306. {
  307. if (glstav_matrix_2d_mod) {
  308. glstav_matrix_2d_mod = FALSE;
  309. glMatrixMode(GL_PROJECTION);
  310. glPopMatrix();
  311. glMatrixMode(GL_MODELVIEW);
  312. glPopMatrix();
  313. }
  314. }
  315. inline void set_matrix_init(void)
  316. {
  317. init_matrix(&__mat_init);
  318. }
  319. inline GLMATRIX *get_matrix_init(void)
  320. {
  321. return (&__mat_init);
  322. }
  323. inline void set_matrix_camera_project(GLMATRIX * p_project)
  324. {
  325. if (__mat_top_matrix_akt) {
  326. mat_mult_dir(__mat_top_matrix + __mat_top_matrix_akt - 1, &__mat_kamera,
  327. &__mat_tmp);
  328. mat_mult_dir(&__mat_tmp, p_project, &__mat_camera_project);
  329. }
  330. else {
  331. mat_mult_dir(&__mat_kamera, p_project, &__mat_camera_project);
  332. }
  333. }
  334. inline GLMATRIX *get_matrix_camera_project(void)
  335. {
  336. return (&__mat_camera_project);
  337. }
  338. /*
  339. Nastaveni cullingu
  340. */
  341. inline void cull_on(void)
  342. {
  343. if (!glstav_cull) {
  344. glEnable(GL_CULL_FACE);
  345. glstav_cull = TRUE;
  346. }
  347. }
  348. inline void cull_off(void)
  349. {
  350. if (glstav_cull) {
  351. glDisable(GL_CULL_FACE);
  352. glstav_cull = FALSE;
  353. }
  354. }
  355. inline void cull_back(void)
  356. {
  357. if (glstav_cull_mod != 1) {
  358. glstav_cull_mod = 1;
  359. glFrontFace(GL_CCW);
  360. }
  361. }
  362. inline void cull_front(void)
  363. {
  364. if (glstav_cull_mod != 2) {
  365. glstav_cull_mod = 2;
  366. glFrontFace(GL_CW);
  367. }
  368. }
  369. inline void cull_nastav(int cull)
  370. {
  371. if (!cull) {
  372. cull_off();
  373. }
  374. else if (cull == 1) {
  375. cull_on();
  376. cull_back();
  377. }
  378. else if (cull == 2) {
  379. cull_on();
  380. cull_front();
  381. }
  382. }
  383. inline void cull_prehod(void)
  384. {
  385. if (glstav_cull_mod) {
  386. if (glstav_cull_mod == 1) {
  387. cull_front();
  388. }
  389. else {
  390. cull_back();
  391. }
  392. }
  393. }
  394. /* Blend-funkce
  395. */
  396. inline void blend_set_one_zero(void)
  397. {
  398. if (glstav_blending) {
  399. glBlendFunc(GL_ONE, GL_ZERO);
  400. }
  401. }
  402. inline void blend_get_default(GLenum * p_src, GLenum * p_dest)
  403. {
  404. *p_src = GL_ONE;
  405. *p_dest = GL_ZERO;
  406. }
  407. inline void blend_set(GLenum src, GLenum dest)
  408. {
  409. if (glstav_blending) {
  410. glBlendFunc(src, dest);
  411. }
  412. }
  413. inline void blend_off(void)
  414. {
  415. if (glstav_blending) {
  416. glstav_blending = FALSE;
  417. glDisable(GL_BLEND);
  418. }
  419. }
  420. inline void blend_on(void)
  421. {
  422. if (!glstav_blending) {
  423. glstav_blending = TRUE;
  424. glEnable(GL_BLEND);
  425. }
  426. }
  427. inline void alfa_test_off(void)
  428. {
  429. if (glstav_alfa_test) {
  430. glstav_alfa_test = FALSE;
  431. glDisable(GL_ALPHA_TEST);
  432. }
  433. }
  434. inline void alfa_test_on(void)
  435. {
  436. if (!glstav_alfa_test) {
  437. glstav_alfa_test = TRUE;
  438. glEnable(GL_ALPHA_TEST);
  439. }
  440. }
  441. inline void blend_param(int stav)
  442. {
  443. if (stav) {
  444. blend_on();
  445. }
  446. else {
  447. blend_off();
  448. }
  449. }
  450. /* Svetla
  451. */
  452. inline void light_ambient_f(float *p_ambient)
  453. {
  454. glLightfv(GL_LIGHT0, GL_AMBIENT, p_ambient);
  455. }
  456. inline void light_ambient_d(dword barva)
  457. {
  458. float amb[4] = { 0, 0, 0, 1 };
  459. rgb_float(barva, amb);
  460. glLightfv(GL_LIGHT0, GL_AMBIENT, amb);
  461. }
  462. inline void light_on_off(int stav)
  463. {
  464. if (stav) {
  465. if (!glstav_lighting) {
  466. glstav_lighting = TRUE;
  467. glEnable(GL_LIGHTING);
  468. }
  469. }
  470. else {
  471. if (glstav_lighting) {
  472. glstav_lighting = FALSE;
  473. glDisable(GL_LIGHTING);
  474. }
  475. }
  476. }
  477. inline void light_shade_smooth(void)
  478. {
  479. glShadeModel(GL_SMOOTH);
  480. }
  481. inline void light_shade_flat(void)
  482. {
  483. glShadeModel(GL_FLAT);
  484. }
  485. /* Mlha
  486. */
  487. void fog_param(int stav);
  488. void fog_on(void);
  489. void fog_off(void);
  490. void aktivuj_mlhu(void);
  491. inline void disable_fog(void);
  492. inline void enable_fog(void);
  493. /* Textury
  494. */
  495. /*
  496. Textury - Sigle-texturing
  497. */
  498. inline void text_init(void)
  499. {
  500. glstav_text_akt = 0;
  501. glstav_textury_1d[0] = TRUE;
  502. glstav_textury_2d[0] = TRUE;
  503. glstav_text_array[0] = FALSE;
  504. glstav_last_text_1d[0] = FALSE;
  505. glstav_last_text_2d[0] = FALSE;
  506. glstav_textury_1d[1] = FALSE;
  507. glstav_textury_2d[1] = FALSE;
  508. glstav_text_array[1] = FALSE;
  509. glstav_last_text_1d[1] = FALSE;
  510. glstav_last_text_2d[1] = FALSE;
  511. glstav_textury_1d[2] = FALSE;
  512. glstav_textury_2d[2] = FALSE;
  513. glstav_text_array[2] = FALSE;
  514. glstav_last_text_1d[2] = FALSE;
  515. glstav_last_text_2d[2] = FALSE;
  516. glstav_textury_1d[3] = FALSE;
  517. glstav_textury_2d[3] = FALSE;
  518. glstav_text_array[3] = FALSE;
  519. glstav_last_text_1d[3] = FALSE;
  520. glstav_last_text_2d[3] = FALSE;
  521. glActiveTextureARB(GL_TEXTURE1_ARB);
  522. glDisable(GL_TEXTURE_1D);
  523. glDisable(GL_TEXTURE_2D);
  524. glActiveTextureARB(GL_TEXTURE0_ARB);
  525. glDisable(GL_TEXTURE_1D);
  526. glDisable(GL_TEXTURE_2D);
  527. }
  528. inline void text_set(GLuint text, GLenum typ)
  529. {
  530. if (typ == GL_TEXTURE_2D) {
  531. if (glstav_textury_2d[glstav_text_akt]
  532. && glstav_last_text_2d[glstav_text_akt] != text) {
  533. glstav_last_text_2d[glstav_text_akt] = text;
  534. glBindTexture(GL_TEXTURE_2D, text);
  535. }
  536. }
  537. else {
  538. if (glstav_textury_1d[glstav_text_akt]
  539. && glstav_last_text_1d[glstav_text_akt] != text) {
  540. glstav_last_text_1d[glstav_text_akt] = text;
  541. glBindTexture(GL_TEXTURE_1D, text);
  542. }
  543. }
  544. }
  545. inline void text_on(GLenum typ)
  546. {
  547. if (typ == GL_TEXTURE_2D) {
  548. if (!glstav_textury_2d[glstav_text_akt]) {
  549. glstav_textury_2d[glstav_text_akt] = TRUE;
  550. glEnable(GL_TEXTURE_2D);
  551. }
  552. if (glstav_textury_1d[glstav_text_akt]) {
  553. glstav_textury_1d[glstav_text_akt] = FALSE;
  554. glDisable(GL_TEXTURE_1D);
  555. }
  556. }
  557. else {
  558. if (!glstav_textury_1d[glstav_text_akt]) {
  559. glstav_textury_1d[glstav_text_akt] = TRUE;
  560. glEnable(GL_TEXTURE_1D);
  561. }
  562. if (glstav_textury_2d[glstav_text_akt]) {
  563. glstav_textury_2d[glstav_text_akt] = FALSE;
  564. glDisable(GL_TEXTURE_2D);
  565. }
  566. }
  567. }
  568. inline void text_off(GLenum typ)
  569. {
  570. if (typ == GL_TEXTURE_2D) {
  571. if (glstav_textury_2d[glstav_text_akt]) {
  572. glstav_textury_2d[glstav_text_akt] = FALSE;
  573. glDisable(GL_TEXTURE_2D);
  574. }
  575. }
  576. else {
  577. if (glstav_textury_1d[glstav_text_akt]) {
  578. glstav_textury_1d[glstav_text_akt] = FALSE;
  579. glDisable(GL_TEXTURE_1D);
  580. }
  581. }
  582. }
  583. inline int text_set_num(int num)
  584. {
  585. if (num < glstav_multitext_units) {
  586. if (glstav_text_akt != num) {
  587. glstav_text_akt = num;
  588. glActiveTextureARB(GL_TEXTURE0_ARB + num);
  589. }
  590. return (TRUE);
  591. }
  592. else {
  593. return (FALSE);
  594. }
  595. }
  596. inline int text_set_num_off(int num)
  597. {
  598. if (num < glstav_multitext_units) {
  599. if (glstav_textury_1d[num] || glstav_textury_2d[num]) {
  600. if (glstav_text_akt != num) {
  601. glstav_text_akt = num;
  602. glActiveTextureARB(GL_TEXTURE0_ARB + num);
  603. }
  604. if (glstav_textury_1d[num]) {
  605. glstav_textury_1d[num] = FALSE;
  606. glDisable(GL_TEXTURE_1D);
  607. }
  608. if (glstav_textury_2d[num]) {
  609. glstav_textury_2d[num] = FALSE;
  610. glDisable(GL_TEXTURE_2D);
  611. }
  612. }
  613. glstav_text_map_indicie[num] = K_CHYBA;
  614. return (TRUE);
  615. }
  616. else {
  617. return (FALSE);
  618. }
  619. }
  620. /* Odrazy
  621. */
  622. inline void specular_on(void)
  623. {
  624. if (!glstav_specular) {
  625. glstav_specular = TRUE;
  626. glEnable(GL_COLOR_SUM_EXT);
  627. }
  628. }
  629. inline void specular_off(void)
  630. {
  631. if (glstav_specular) {
  632. glstav_specular = FALSE;
  633. glDisable(GL_COLOR_SUM_EXT);
  634. }
  635. }
  636. inline void specular_color(float r, float g, float b)
  637. {
  638. glSecondaryColor3fEXT(r, g, b);
  639. glDisable(GL_COLOR_SUM_EXT);
  640. }
  641. /* Diffusni barvy
  642. */
  643. inline void diffuse_off(float r, float g, float b, float a)
  644. {
  645. glstav_diffuse = FALSE;
  646. glColor4f(r, g, b, a);
  647. }
  648. inline void diffuse_on(void)
  649. {
  650. glstav_diffuse = TRUE;
  651. }
  652. /*
  653. Rendering z poli
  654. */
  655. inline void array_specular_set(int stav)
  656. {
  657. if (stav) {
  658. if (!glstav_array_specular) {
  659. glstav_array_specular = TRUE;
  660. glEnableClientState(GL_SECONDARY_COLOR_ARRAY_EXT);
  661. }
  662. }
  663. else {
  664. if (glstav_array_specular) {
  665. glstav_array_specular = FALSE;
  666. glDisableClientState(GL_SECONDARY_COLOR_ARRAY_EXT);
  667. }
  668. }
  669. }
  670. inline void array_specular_on(void)
  671. {
  672. if (!glstav_array_specular) {
  673. glstav_array_specular = TRUE;
  674. glEnableClientState(GL_SECONDARY_COLOR_ARRAY_EXT);
  675. }
  676. }
  677. inline void array_specular_off(void)
  678. {
  679. if (glstav_array_specular) {
  680. glstav_array_specular = FALSE;
  681. glDisableClientState(GL_SECONDARY_COLOR_ARRAY_EXT);
  682. }
  683. }
  684. inline void array_diffuse_on(void)
  685. {
  686. if (!glstav_array_diffuse) {
  687. glstav_array_diffuse = TRUE;
  688. glEnableClientState(GL_COLOR_ARRAY);
  689. }
  690. }
  691. inline void array_diffuse_off(void)
  692. {
  693. if (glstav_array_diffuse) {
  694. glstav_array_diffuse = FALSE;
  695. glDisableClientState(GL_COLOR_ARRAY);
  696. }
  697. }
  698. /* Normalove vektory
  699. */
  700. inline void array_normal_set(int stav)
  701. {
  702. if (stav) {
  703. if (!glstav_array_normal) {
  704. glstav_array_normal = TRUE;
  705. glEnableClientState(GL_NORMAL_ARRAY);
  706. }
  707. }
  708. else {
  709. if (glstav_array_normal) {
  710. glstav_array_normal = FALSE;
  711. glDisableClientState(GL_NORMAL_ARRAY);
  712. }
  713. }
  714. }
  715. inline void array_normal_on(void)
  716. {
  717. if (!glstav_array_normal) {
  718. glstav_array_normal = TRUE;
  719. glEnableClientState(GL_NORMAL_ARRAY);
  720. }
  721. }
  722. inline void array_normal_off(void)
  723. {
  724. if (glstav_array_normal) {
  725. glstav_array_normal = FALSE;
  726. glDisableClientState(GL_NORMAL_ARRAY);
  727. }
  728. }
  729. /* Vertex-listy
  730. */
  731. inline int array_text_set_num(int num)
  732. {
  733. if (num < glstav_multitext_units) {
  734. if (num != glstav_text_array_akt) {
  735. glstav_text_array_akt = num;
  736. glClientActiveTextureARB(GL_TEXTURE0_ARB + num);
  737. }
  738. return (TRUE);
  739. }
  740. else
  741. return (FALSE);
  742. }
  743. inline void array_text_on(void)
  744. {
  745. if (!glstav_text_array[glstav_text_array_akt]) {
  746. glstav_text_array[glstav_text_array_akt] = TRUE;
  747. glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  748. }
  749. }
  750. inline void array_text_off(void)
  751. {
  752. if (glstav_text_array[glstav_text_array_akt]) {
  753. glstav_text_array[glstav_text_array_akt] = FALSE;
  754. glDisableClientState(GL_TEXTURE_COORD_ARRAY);
  755. }
  756. }
  757. /* Mlha
  758. */
  759. inline void nastav_fog(MLZNA_KOSTKA * p_mlha)
  760. {
  761. if (p_mlha) {
  762. glFogi(GL_FOG_MODE, p_mlha->mod);
  763. glFogfv(GL_FOG_COLOR, &p_mlha->r);
  764. glFogf(GL_FOG_DENSITY, p_mlha->intenzita);
  765. glFogf(GL_FOG_START, p_mlha->start);
  766. glFogf(GL_FOG_END, p_mlha->stop);
  767. }
  768. }
  769. inline void disable_fog(void)
  770. {
  771. if (glstav_mlha) {
  772. glDisable(GL_FOG);
  773. glstav_mlha = FALSE;
  774. }
  775. }
  776. inline void enable_fog(void)
  777. {
  778. if (!glstav_mlha) {
  779. glEnable(GL_FOG);
  780. glstav_mlha = TRUE;
  781. }
  782. }
  783. inline void disable_fog_causal(void)
  784. {
  785. if (glstav_mlha && glstav_mlha_causal) {
  786. glstav_mlha_causal = FALSE;
  787. glDisable(GL_FOG);
  788. }
  789. }
  790. inline void enable_fog_causal(void)
  791. {
  792. if (glstav_mlha && !glstav_mlha_causal) {
  793. glstav_mlha_causal = TRUE;
  794. glEnable(GL_FOG);
  795. }
  796. }
  797. inline void text_sharp(float sharp)
  798. {
  799. sharp = -sharp;
  800. int i;
  801. for (i = 0; i < glstav_multitext_units; i++) {
  802. text_set_num(i);
  803. glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, sharp);
  804. }
  805. }
  806. inline void reset_kamera_flag(void)
  807. {
  808. glstav_zmena_kamery = FALSE;
  809. }
  810. /*
  811. #define TEXGEN_NIC 0
  812. #define TEXGEN_SPHEREMAP 1
  813. #define TEXGEN_EYE_LINEAR 2
  814. */
  815. inline void texgen_env_on(int num)
  816. {
  817. if (glstav_genenv_s[num] != TEXGEN_SPHEREMAP) {
  818. glstav_genenv_s[num] = TEXGEN_SPHEREMAP;
  819. glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
  820. glEnable(GL_TEXTURE_GEN_S);
  821. }
  822. if (glstav_genenv_t[num] != TEXGEN_SPHEREMAP) {
  823. glstav_genenv_t[num] = TEXGEN_SPHEREMAP;
  824. glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
  825. glEnable(GL_TEXTURE_GEN_T);
  826. }
  827. if (glstav_genenv_r[num]) {
  828. glstav_genenv_r[num] = FALSE;
  829. glDisable(GL_TEXTURE_GEN_R);
  830. }
  831. if (glstav_genenv_q[num]) {
  832. glstav_genenv_q[num] = FALSE;
  833. glDisable(GL_TEXTURE_GEN_Q);
  834. }
  835. }
  836. // Musi se nastavit transformacni matice pro transformace tech souradnic
  837. inline void texgen_linear_eye_2d_on(int num, float *p_spar, float *p_tpar)
  838. {
  839. GLMATRIX *p_mat = glstav_texgen + num;
  840. if (!glstav_genenv_s[num])
  841. glEnable(GL_TEXTURE_GEN_S);
  842. if (!glstav_genenv_t[num])
  843. glEnable(GL_TEXTURE_GEN_T);
  844. if (glstav_genenv_s[num] != TEXGEN_EYE_LINEAR) {
  845. glstav_genenv_s[num] = TEXGEN_EYE_LINEAR;
  846. glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
  847. }
  848. if (glstav_genenv_t[num] != TEXGEN_EYE_LINEAR) {
  849. glstav_genenv_t[num] = TEXGEN_EYE_LINEAR;
  850. glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
  851. }
  852. if (glstav_zmena_kamery ||
  853. p_spar[0] != p_mat->_11 || p_spar[1] != p_mat->_21 ||
  854. p_spar[2] != p_mat->_31 || p_spar[3] != p_mat->_41 ||
  855. p_tpar[0] != p_mat->_12 || p_tpar[1] != p_mat->_22 ||
  856. p_tpar[2] != p_mat->_32 || p_tpar[3] != p_mat->_42) {
  857. p_mat->_11 = p_spar[0];
  858. p_mat->_21 = p_spar[1];
  859. p_mat->_31 = p_spar[2];
  860. p_mat->_41 = p_spar[3];
  861. p_mat->_12 = p_tpar[0];
  862. p_mat->_22 = p_tpar[1];
  863. p_mat->_32 = p_tpar[2];
  864. p_mat->_42 = p_tpar[3];
  865. glMatrixMode(GL_MODELVIEW);
  866. glLoadMatrixf((float *) &__mat_kamera);
  867. glTexGenfv(GL_S, GL_EYE_PLANE, p_spar);
  868. glTexGenfv(GL_T, GL_EYE_PLANE, p_tpar);
  869. glLoadMatrixf((float *) &__mat_vysl);
  870. }
  871. if (glstav_genenv_r[num]) {
  872. glstav_genenv_r[num] = FALSE;
  873. glDisable(GL_TEXTURE_GEN_R);
  874. }
  875. if (glstav_genenv_q[num]) {
  876. glstav_genenv_q[num] = FALSE;
  877. glDisable(GL_TEXTURE_GEN_Q);
  878. }
  879. }
  880. inline void texgen_off(int num)
  881. {
  882. if (glstav_genenv_s[num]) {
  883. glstav_genenv_s[num] = FALSE;
  884. glDisable(GL_TEXTURE_GEN_S);
  885. }
  886. if (glstav_genenv_t[num]) {
  887. glstav_genenv_t[num] = FALSE;
  888. glDisable(GL_TEXTURE_GEN_T);
  889. }
  890. if (glstav_genenv_r[num]) {
  891. glstav_genenv_r[num] = FALSE;
  892. glDisable(GL_TEXTURE_GEN_R);
  893. }
  894. if (glstav_genenv_q[num]) {
  895. glstav_genenv_q[num] = FALSE;
  896. glDisable(GL_TEXTURE_GEN_Q);
  897. }
  898. }
  899. inline void deph_test_set(int stav)
  900. {
  901. if (stav) {
  902. if (!glstav_deph_test) {
  903. glstav_deph_test = TRUE;
  904. glEnable(GL_DEPTH_TEST);
  905. }
  906. }
  907. else {
  908. if (glstav_deph_test) {
  909. glstav_deph_test = FALSE;
  910. glDisable(GL_DEPTH_TEST);
  911. }
  912. }
  913. }
  914. inline void zmask_set(int stav)
  915. {
  916. if (stav) {
  917. if (!glstav_zmask) {
  918. glstav_zmask = TRUE;
  919. glDepthMask(TRUE);
  920. }
  921. }
  922. else {
  923. if (glstav_zmask) {
  924. glstav_zmask = FALSE;
  925. glDepthMask(FALSE);
  926. }
  927. }
  928. }
  929. inline void zmask_set_fleky(int stav)
  930. {
  931. glDepthMask((GLboolean) stav);
  932. }
  933. inline void set_alfa_blok(int blok)
  934. {
  935. if (blok != glstav_alfa_blok) {
  936. glstav_alfa_blok = blok;
  937. p_alfa_stage_func[alfa_stage_edit_blok[blok].funkce] ();
  938. }
  939. }
  940. inline void text_set_blok(int text, int blok)
  941. {
  942. if (blok != glstav_text_blok[text]) {
  943. glstav_text_blok[text] = blok;
  944. p_text_stage_func_elem[blok] ();
  945. }
  946. }
  947. inline void text_stage_func_nic(int last_text)
  948. {
  949. int i = last_text;
  950. if (i != K_CHYBA) {
  951. for (; i < MAT_TEXTUR; i++) {
  952. if (!text_set_num_off(i))
  953. return;
  954. }
  955. }
  956. }
  957. inline void reset_stage_bloky(void)
  958. {
  959. glstav_alfa_blok = K_CHYBA;
  960. glstav_text_blok[0] = K_CHYBA;
  961. glstav_text_blok[0] = K_CHYBA;
  962. glstav_text_blok[1] = K_CHYBA;
  963. glstav_text_blok[2] = K_CHYBA;
  964. glstav_text_blok[3] = K_CHYBA;
  965. glstav_text_blok[4] = K_CHYBA;
  966. glstav_text_blok[5] = K_CHYBA;
  967. }
  968. inline void text_set_num_poly(int num)
  969. {
  970. text_set_num(num);
  971. text_on(GL_TEXTURE_2D);
  972. text_set_blok(num, BLOK_MODULACE);
  973. ret_matrix_texture(num);
  974. texgen_off(num);
  975. glstav_text_poly_indicie = num;
  976. }
  977. inline void text_stage_func_nic_poly(int last_text, int poly_text)
  978. {
  979. int i = last_text;
  980. if (i != K_CHYBA) {
  981. for (; i < MAT_TEXTUR; i++) {
  982. if (!text_set_num_off(i)) {
  983. break;
  984. }
  985. }
  986. }
  987. text_set_num_poly(poly_text);
  988. }
  989. /* Vertexove pole
  990. */
  991. void vertex_array_ini(void);
  992. extern void (*mesh_vertex_array_init) (GAME_MESH_OLD * p_mesh);
  993. extern void (*mesh_vertex_array_zrus) (GAME_MESH_OLD * p_mesh);
  994. extern void (*mesh_vertex_array_upload) (GAME_MESH_OLD * p_mesh);
  995. extern void (*mesh_vertex_array_set) (GAME_MESH_OLD * p_mesh);
  996. extern void (*mesh_vertex_array_set_koord) (GAME_MESH_OLD * p_mesh);
  997. extern void (*poly_vertex_array_init) (EDIT_MESH_POLY * p_poly);
  998. extern void (*poly_vertex_array_zrus) (EDIT_MESH_POLY * p_poly);
  999. extern void (*poly_vertex_array_upload) (EDIT_MESH_POLY * p_poly);
  1000. extern void (*poly_vertex_array_set) (EDIT_MESH_POLY * p_poly);
  1001. extern void (*vertex_array_start_render) (void);
  1002. extern void (*vertex_array_stop_render) (void);
  1003. #define BUFFER_OFFSET(i) ((char *)NULL + (i))
  1004. #endif