source: golgotha/src/test/gtext_viewer/gtext_viewer.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 14 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 2.7 KB
Line 
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
9#include "window/window.hh"
10#include "app/app.hh"
11#include "main/main.hh"
12#include "window/style.hh"
13#include "file/file.hh"
14#include "loaders/load.hh"
15#include "window/wmanager.hh"
16#include "math/transform.hh"
17#include "gui/text.hh"
18#include "gui/button.hh"
19#include "gui/image_win.hh"
20#include "loaders/load.hh"
21
22#include "r1_res.hh"
23#include "image/image16.hh"
24#include "tex_cache.hh"
25#include "tex_id.hh"
26#include "mip.hh"
27
28int load_gtext(i4_const_str texture_name, i4_image_class **images)
29{
30  i4_file_class *fp;
31  tex_cache_header_t theader;
32  mipheader_t header;
33
34  fp=i4_open(r1_gets("texture_cache"));
35  if (!fp)
36    return 0;
37
38  theader.read(fp);
39  delete fp;
40
41  w32 id=r1_get_texture_id(texture_name);
42  i4_str *fn = r1_texture_id_to_filename(id, r1_gets("local_texture_dir"));
43  fp=i4_open(*fn);
44  delete fn;
45  if (!fp)
46    return 0;
47
48  header.read(fp);
49
50  int w=header.base_width, h=header.base_height, i;
51  i4_pal *pal;
52
53  if (header.flags & R1_MIP_IS_TRANSPARENT)   
54    pal=i4_pal_man.register_pal(&theader.chroma_format);
55  else if (header.flags & R1_MIP_IS_ALPHATEXTURE)
56    pal=i4_pal_man.register_pal(&theader.alpha_format);
57  else
58    pal=i4_pal_man.register_pal(&theader.regular_format);
59
60  for (i=0; i<header.num_mip_levels; i++)
61  {
62    fp->seek(header.offsets[i]+8);
63   
64    w16 *data=(w16 *)i4_malloc(w*h*2,"");
65    fp->read(data,w*h*2);
66
67   
68    i4_image16 *im=new i4_image16(w,h, pal, (w8 *)data, w*2);
69    im->dont_free_data=i4_T;
70   
71    images[i]=im;
72    w/=2;
73    h/=2;
74  }
75  delete fp;
76
77  return header.num_mip_levels;
78}
79
80extern i4_image_class *global_im;
81class test_app : public i4_application_class
82{
83public:
84  void init()
85  {
86    i4_application_class::init();
87
88    i4_image_class *im[10];
89   
90    int t = load_gtext("explosions2.tga", im);
91    //i4_image_class *im=i4_load_image("/u/crack/golgotha/textures/moon.tga");
92   
93    int x=0;
94    for (int i=0; i<t; i++)
95    {
96      i4_image_window_class *im_win=new i4_image_window_class(im[i], i4_T, i4_F);
97     
98      wm->add_child(x,0, im_win);
99      x+=im[i]->width();
100
101    }
102
103  } 
104
105
106  char *name() { return "test_app"; }
107};
108
109void i4_main(w32 argc, i4_const_str *argv)
110{
111  test_app test;
112  test.run();
113}
114
Note: See TracBrowser for help on using the repository browser.