gtext_viewer.cc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /********************************************************************** <BR>
  2. This file is part of Crack dot Com's free source code release of
  3. Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
  4. information about compiling & licensing issues visit this URL</a>
  5. <PRE> If that doesn't help, contact Jonathan Clark at
  6. golgotha_source@usa.net (Subject should have "GOLG" in it)
  7. ***********************************************************************/
  8. #include "window/window.hh"
  9. #include "app/app.hh"
  10. #include "main/main.hh"
  11. #include "window/style.hh"
  12. #include "file/file.hh"
  13. #include "loaders/load.hh"
  14. #include "window/wmanager.hh"
  15. #include "math/transform.hh"
  16. #include "gui/text.hh"
  17. #include "gui/button.hh"
  18. #include "gui/image_win.hh"
  19. #include "loaders/load.hh"
  20. #include "r1_res.hh"
  21. #include "image/image16.hh"
  22. #include "tex_cache.hh"
  23. #include "tex_id.hh"
  24. #include "mip.hh"
  25. int load_gtext(i4_const_str texture_name, i4_image_class **images)
  26. {
  27. i4_file_class *fp;
  28. tex_cache_header_t theader;
  29. mipheader_t header;
  30. fp=i4_open(r1_gets("texture_cache"));
  31. if (!fp)
  32. return 0;
  33. theader.read(fp);
  34. delete fp;
  35. w32 id=r1_get_texture_id(texture_name);
  36. i4_str *fn = r1_texture_id_to_filename(id, r1_gets("local_texture_dir"));
  37. fp=i4_open(*fn);
  38. delete fn;
  39. if (!fp)
  40. return 0;
  41. header.read(fp);
  42. int w=header.base_width, h=header.base_height, i;
  43. i4_pal *pal;
  44. if (header.flags & R1_MIP_IS_TRANSPARENT)
  45. pal=i4_pal_man.register_pal(&theader.chroma_format);
  46. else if (header.flags & R1_MIP_IS_ALPHATEXTURE)
  47. pal=i4_pal_man.register_pal(&theader.alpha_format);
  48. else
  49. pal=i4_pal_man.register_pal(&theader.regular_format);
  50. for (i=0; i<header.num_mip_levels; i++)
  51. {
  52. fp->seek(header.offsets[i]+8);
  53. w16 *data=(w16 *)i4_malloc(w*h*2,"");
  54. fp->read(data,w*h*2);
  55. i4_image16 *im=new i4_image16(w,h, pal, (w8 *)data, w*2);
  56. im->dont_free_data=i4_T;
  57. images[i]=im;
  58. w/=2;
  59. h/=2;
  60. }
  61. delete fp;
  62. return header.num_mip_levels;
  63. }
  64. extern i4_image_class *global_im;
  65. class test_app : public i4_application_class
  66. {
  67. public:
  68. void init()
  69. {
  70. i4_application_class::init();
  71. i4_image_class *im[10];
  72. int t = load_gtext("explosions2.tga", im);
  73. //i4_image_class *im=i4_load_image("/u/crack/golgotha/textures/moon.tga");
  74. int x=0;
  75. for (int i=0; i<t; i++)
  76. {
  77. i4_image_window_class *im_win=new i4_image_window_class(im[i], i4_T, i4_F);
  78. wm->add_child(x,0, im_win);
  79. x+=im[i]->width();
  80. }
  81. }
  82. char *name() { return "test_app"; }
  83. };
  84. void i4_main(w32 argc, i4_const_str *argv)
  85. {
  86. test_app test;
  87. test.run();
  88. }