/[cvs]/api/Classes/Engine3d/TextureData.cpp
ViewVC logotype

Annotation of /api/Classes/Engine3d/TextureData.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Sun Jul 1 20:47:58 2001 UTC (23 years, 4 months ago) by bearsoft
Branch point for: lazy, MAIN
Initial revision

1 bearsoft 1.1 #include <stdio.h>
2     #include "TextureData.h"
3    
4     TextureData::TextureData( char *texturedataname )
5     {
6     numberoftextures=1;
7     texturesize = new int[numberoftextures];
8     texturewidth = new int[numberoftextures];
9     textureheight = new int[numberoftextures];
10    
11     readfile(texturedataname,0);
12     }
13    
14     TextureData::~TextureData(){}
15    
16     void TextureData::setpointertexture(int *ipointertexture) { pointertexture=ipointertexture;}
17     int *TextureData::getpointertexture() { return pointertexture; }
18    
19     void TextureData::settexturesize(int isize, int steg) { texturesize[steg]=isize;}
20     int TextureData::gettexturesize(int steg) { return texturesize[steg]; }
21    
22     void TextureData::settexturewidth(int iwidth, int steg) { texturewidth[steg]=iwidth;}
23     int TextureData::gettexturewidth(int steg) { return texturewidth[steg]; }
24    
25     void TextureData::settextureheight(int iheight, int steg) { textureheight[steg]=iheight;}
26     int TextureData::gettextureheight(int steg) { return textureheight[steg]; }
27    
28     int TextureData::getnumberoftextures() { return numberoftextures; }
29    
30     void TextureData::readpicture(char *chunkybuffer, int langd, int width, int height, unsigned char* kbuffer )
31     {
32     int d1l,d3l;
33    
34     unsigned char *k,*alpha,*red,*green,*blue;
35    
36     d1l=(langd-512)/4;
37    
38     k=kbuffer+512;
39     red=k+d1l;
40     green=k+(d1l*2);
41     blue=k+(d1l*3);
42     alpha=k+(d1l*4);
43    
44     for ( int d7l=0 ; d7l<height ; d7l++ )
45     {
46    
47     d3l=width*4;
48    
49     for ( int d2l=0 ; d2l<width ; d2l++ )
50     {
51     d3l=d3l-4;
52    
53     --alpha;
54     chunkybuffer[d3l+3]=alpha[0]; //alpha
55    
56     --red;
57     chunkybuffer[d3l+2]=red[0]; //red
58    
59     --green;
60     chunkybuffer[d3l+1]=green[0]; //green
61    
62     --blue;
63     chunkybuffer[d3l]=blue[0]; //blue
64    
65     }
66    
67     chunkybuffer=chunkybuffer+(width*4);
68     }
69    
70     }
71    
72    
73     void TextureData::readfile(char *filename, int filenumber )
74     {
75     FILE *f;
76    
77     f = fopen(filename, "rb");
78    
79     fseek(f,0,2);
80     settexturesize(ftell(f), filenumber);
81     fseek(f,0,0);
82    
83     unsigned char *bbuffer = new unsigned char[gettexturesize(filenumber)];
84     int *bbuffer2 = new int[gettexturesize(filenumber)*4];
85    
86     fread((void *) bbuffer, gettexturesize(filenumber), 1, f);
87     fclose(f);
88    
89     char *dbuffer=(char*)bbuffer;
90     dbuffer=dbuffer+(3*2);
91    
92     char d=dbuffer[0];
93     dbuffer[0]=dbuffer[1];
94     dbuffer[1]=d;
95    
96     short *xbuffer=(short*)dbuffer;
97    
98     dbuffer=dbuffer+(1*2);
99    
100     d=dbuffer[0];
101     dbuffer[0]=dbuffer[1];
102     dbuffer[1]=d;
103    
104     short *ybuffer=(short*)dbuffer;
105    
106     readpicture((char*) bbuffer2, gettexturesize(filenumber), (int) xbuffer[0], (int) ybuffer[0], bbuffer );
107    
108     settexturesize(256*256*4,filenumber);
109     settexturewidth(256,filenumber);
110     settextureheight(256,filenumber);
111    
112     int *temppointer= new int[gettexturesize(filenumber)];
113    
114     setpointertexture(temppointer);
115    
116     float ustep=(float)xbuffer[0]/(float)gettexturewidth(filenumber);
117     float vstep=(float)ybuffer[0]/(float)gettextureheight(filenumber);
118    
119     int *pointer=(int*)getpointertexture();
120     float v=0;
121    
122     for ( int y=0 ; y<256; y++ )
123     {
124     float u=0;
125     for ( int x=0 ; x<256 ; x++ )
126     {
127     int tempu=(int)u;
128     int tempv=(int)v;
129     pointer[x+y*256]=bbuffer2[tempu+tempv*xbuffer[0]];
130     u+=ustep;
131     }
132     v+=vstep;
133     }
134    
135    
136     delete bbuffer2;
137     delete bbuffer;
138     }
139    
140    
141    

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26