Texture.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /*
  2. Header s texturam
  3. */
  4. #ifndef __TEXTURE_H__
  5. #define __TEXTURE_H__
  6. #define DEF_MIP_LEVEL 9
  7. // ABGR poradi slozek
  8. typedef struct _RBITMAP
  9. {
  10. int x, y;
  11. dword *data;
  12. float *data_float;
  13. } RBITMAP;
  14. typedef RBITMAP bitmapa;
  15. #define TEXT_GEN_DOT3 0x0001 //textura se prevede na dot3
  16. #define TEXT_GEN_DUDV 0x0002 //textura se prevede na dudv
  17. #define TEXT_FLOYD 0x0004 //aplikovat floyda
  18. #define TEXT_GEN (TEXT_GEN_DOT3|TEXT_GEN_DUDV)
  19. #define TEXT2_POUZITA 0x0001
  20. #define TEXT2_FLARE 0x0002
  21. typedef struct _EDIT_TEXT_OLD
  22. {
  23. char jmeno[MAX_JMENO]; //jmeno textury
  24. bitmapa *p_bmp; // pointer na bitmapu textury
  25. GLuint text; // jmeno textury
  26. GLenum typ; // typ textury (1D/2D)
  27. byte load; // = 1 text je nahrana, 0 - neni nahrana
  28. int flag; // flag - TEXT_GEN_DOT3/....
  29. int flag2; // flag - pouzita/flare...
  30. GLint format; // format texury
  31. int trida; // trida textury
  32. int mip; // mip_mapping
  33. int mip_filtr; // filtr aplikovany na mip-mapy
  34. int std_filtr; // std filtr
  35. GLint wrap_x; // wrap/clamp
  36. GLint wrap_y;
  37. int bump;
  38. int alfa_stage; // alfa-stage z textury
  39. int no_cull; // bez culingu
  40. int floyd;
  41. int floyd_transp;
  42. } EDIT_TEXT, EDIT_TEXT_OLD;
  43. // Konfigurace textury pro nahrani z disku (format&pod.)
  44. typedef struct _EDIT_TEXT_KONFIG
  45. {
  46. char bitmapa[200]; // bitmapa
  47. char alfamap[200]; // alfamapa textury
  48. GLenum typ; // typ textury (1D/2D/3D/4D/5D/6D)
  49. GLint format; // format texury
  50. GLint wrap_x; // wrap/clamp
  51. GLint wrap_y;
  52. int mip; // mip_mapping
  53. int mip_filtr; // filtr aplikovany na mip-mapy
  54. int alfa; // alfa kanal ?
  55. int std_filtr;
  56. int bump;
  57. int alfa_stage; // alfa-stage z textury
  58. int no_cull; // bez culingu
  59. int floyd;
  60. int floyd_transp;
  61. } EDIT_TEXT_KONFIG;
  62. #define KONCOVKA_TEXT_INFO ".btx"
  63. #define MASKA_TEXT_INFO "*.btx"
  64. #define KONCOVKA_ALFA "_a"
  65. #define TEXT_16BPP 16
  66. #define TEXT_32BPP 32
  67. #define TEXT_DTX 128
  68. void txt_lightmap_konfig(EDIT_TEXT_KONFIG * p_konf);
  69. bitmapa *txt_bmp2textura(bitmapa * p_bmp, EDIT_TEXT_OLD * p_text,
  70. EDIT_TEXT_KONFIG * p_konf, int _2d_text);
  71. int txt_reload_lightmap(EDIT_TEXT_OLD * p_text, bitmapa * p_bmp);
  72. int txt_nahraj_texturu_do_vram(EDIT_TEXT_OLD * p_text,
  73. EDIT_TEXT_KONFIG * p_konf);
  74. int txt_zrus_texturu_z_vram(EDIT_TEXT_OLD * p_text);
  75. int txt_nahraj_lightmapu_z_bmp(char *p_file, KFILE * f,
  76. EDIT_TEXT_OLD * p_text, int save);
  77. int txt_nahraj_texturu_z_func(APAK_HANDLE * pHandle, const char *p_file,
  78. EDIT_TEXT_OLD * p_text, int save, int load, EDIT_TEXT_KONFIG * p_konf,
  79. bitmapa * (*p_load) (APAK_HANDLE * pAHandle, char *p_file));
  80. int txt_nahraj_texturu_z_dds(APAK_HANDLE * pHandle, char *p_file,
  81. EDIT_TEXT_OLD * p_text, int save);
  82. int txt_nahraj_texturu_z_lib(APAK_HANDLE * pHandle, char *p_file,
  83. EDIT_TEXT_OLD * p_text, int save);
  84. int txt_nahraj_texturu_z_tga(APAK_HANDLE * pHandle, char *p_file,
  85. EDIT_TEXT_OLD * p_text);
  86. int txt_nahraj_texturu_dot3(APAK_HANDLE * pHandle, char *p_file,
  87. EDIT_TEXT_OLD * p_text, int save);
  88. int txt_to_dot3(EDIT_TEXT_OLD * p_text, int save);
  89. int txt_uvolni_texturu(EDIT_TEXT_OLD * p_text);
  90. int txt_zrus_texturu(EDIT_TEXT_OLD * p_text);
  91. int txt_zrus_texturu_ram(EDIT_TEXT_OLD * p_text);
  92. bitmapa *txt_bmp2dot3(bitmapa * p_bmp);
  93. void txt_default_konfig(char *p_file, EDIT_TEXT_KONFIG * p_konf,
  94. char *p_koncovka);
  95. int txt_uloz_btx(char *p_file, int typ, int wrap_x, int wrap_y);
  96. int txt_kopiruj(EDIT_TEXT_OLD * p_dest, EDIT_TEXT_OLD * p_src);
  97. int txt_vyrob_2D_texturu(int x, int y, int filtr, int format);
  98. int txt_zrus_2D_texturu(int *p_text);
  99. int txt_zrus_lightmapu(EDIT_TEXT_OLD * p_text);
  100. byte *file_read(APAK_HANDLE * pHandle, char *p_file, int *p_read);
  101. bitmapa *bmp_vyrob(int x, int y);
  102. bitmapa *bmp_nahraj(char *p_file);
  103. bitmapa *bmp_nahraj(APAK_HANDLE * pAHandle, char *p_file);
  104. bitmapa *bmp_nahraj(KFILE * f);
  105. int bmp_uloz(char *p_file, bitmapa * p_bmp);
  106. int bmp_uloz_pack(FFILE f, bitmapa * p_bmp);
  107. void bmp_zrus(bitmapa ** p_bmp);
  108. bitmapa *bmp_kopituj(bitmapa * p_bmp);
  109. inline void bmp_cti_rozmery(bitmapa * p_bmp, int *p_x, int *p_y);
  110. inline int bmp_velikost(bitmapa * p_bmp);
  111. bitmapa *bmp_prehod(bitmapa * p_bmp);
  112. typedef struct _bitmapa_pixel
  113. {
  114. byte r, g, b, a;
  115. } bitmapa_pixel;
  116. /*
  117. inline dword barva_to_bmp(dword barva)
  118. {
  119. return((barva << 8)|(barva >> 24));
  120. }
  121. */
  122. inline dword *bmp_getpixel_ref(bitmapa * p_bmp, int x, int y)
  123. {
  124. return (p_bmp->data + (p_bmp->x * y + x));
  125. }
  126. inline dword bmp_getpixel(bitmapa * p_bmp, int x, int y)
  127. {
  128. return (p_bmp->data[p_bmp->x * y + x]);
  129. }
  130. inline bitmapa_pixel bmp_getpixel_pix(bitmapa * p_bmp, int x, int y)
  131. {
  132. bitmapa_pixel *p_pix = (bitmapa_pixel *) p_bmp->data;
  133. return (p_pix[p_bmp->x * y + x]);
  134. }
  135. inline void bmp_putpixel(bitmapa * p_bmp, int x, int y, dword barva)
  136. {
  137. p_bmp->data[p_bmp->x * y + x] = barva;
  138. }
  139. inline void bmp_putpixel_pix(bitmapa * p_bmp, int x, int y,
  140. bitmapa_pixel barva)
  141. {
  142. bitmapa_pixel *p_pix = (bitmapa_pixel *) p_bmp->data;
  143. p_pix[p_bmp->x * y + x] = barva;
  144. }
  145. inline void bmp_cti_rozmery(bitmapa * p_bmp, int *p_x, int *p_y)
  146. {
  147. if (p_bmp) {
  148. *p_x = p_bmp->x;
  149. *p_y = p_bmp->y;
  150. }
  151. else {
  152. *p_x = 0;
  153. *p_y = 0;
  154. }
  155. }
  156. // kopiruje bitmapu do druhe vetsi na zadane souradnice
  157. // src->dest
  158. inline void bmp_kopiruj_rec(bitmapa * p_src, bitmapa * p_desc, int xp, int yp)
  159. {
  160. int x, y;
  161. for (x = 0; x < p_src->x; x++) {
  162. for (y = 0; y < p_src->y; y++) {
  163. bmp_putpixel(p_desc, x + xp, y + yp, bmp_getpixel(p_src, x, y));
  164. }
  165. }
  166. }
  167. // src->dest
  168. inline void bmp_vyber_rec(bitmapa * p_src, bitmapa * p_desc, int xp, int yp)
  169. {
  170. int x, y;
  171. for (x = 0; x < p_desc->x; x++) {
  172. for (y = 0; y < p_desc->y; y++) {
  173. bmp_putpixel(p_desc, x, y, bmp_getpixel(p_src, x + xp, y + yp));
  174. }
  175. }
  176. }
  177. // kopie src->desc
  178. inline void bmp_kopiruj(bitmapa * p_src, bitmapa * p_desc)
  179. {
  180. p_desc->x = p_src->x;
  181. p_desc->y = p_src->y;
  182. memcpy(p_desc->data, p_src->data, sizeof(dword) * p_src->x * p_src->y);
  183. }
  184. inline void bmp_smaz(bitmapa * p_text, dword barva)
  185. {
  186. int i, n = p_text->x * p_text->y;
  187. dword *p_col = p_text->data;
  188. for (i = 0; i < n; i++, p_col++)
  189. *p_col = barva;
  190. }
  191. inline byte PackFloatInByte(float in)
  192. {
  193. return (byte) ((in + 1.0f) / 2.0f * 255.0f);
  194. }
  195. inline int bmp_velikost(bitmapa * p_bmp)
  196. {
  197. return (p_bmp->x * p_bmp->y * 4);
  198. }
  199. void bmp_to_16bit(bitmapa * p_bmp, byte maska, int pruh);
  200. /*
  201. #define TEXT_MENU 0
  202. #define TEXT_SYSTEM 1
  203. #define TEXT_PRVKY 2
  204. #define TEXT_SCENA 3
  205. #define TEXT_LIGHT 4
  206. #define TEXT_TRID 5
  207. */
  208. void txt_trida(int trida);
  209. #endif