00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "Teddy/Graphics/PixFileTexture.h"
00026 #include "Teddy/Graphics/Device.h"
00027 #include "Teddy/SysSupport/EndianIn.h"
00028 #include "Teddy/SysSupport/Messages.h"
00029 #include "Teddy/SysSupport/StdIO.h"
00030 using namespace Teddy::Maths;
00031 using namespace Teddy::SysSupport;
00032
00033
00034 namespace Teddy {
00035 namespace Graphics {
00036
00037
00039 PixFileTexture::PixFileTexture( const std::string &fname ):Texture(fname){
00040 EndianIn *s = NULL;
00041 unsigned char *filler = NULL;
00042 unsigned char *data = NULL;
00043 unsigned char byte_in;
00044 unsigned char color_table[256*4];
00045 unsigned char index;
00046 int i = 0;
00047
00048
00049 try{
00050 s = new EndianIn( "Data/buda_textures/iwarflip.pal" );
00051 s->set_bigendian();
00052
00053
00054 for( i=0; i<24; i++ ){
00055 s->read_byte();
00056 }
00057
00058
00059 for( i=0; i<256;i++ ){
00060 color_table[i*4+0] = s->read_byte();
00061 color_table[i*4+1] = s->read_byte();
00062 color_table[i*4+2] = s->read_byte();
00063 color_table[i*4+3] = s->read_byte();
00064 }
00065 }catch( ... ){
00066 emsg( M_MAT, "Error loading iwarflip.pal, got as far as i = %d", i );
00067 }
00068 delete s;
00069
00070 this->size = Vector2( 256, 256 );
00071
00072
00073 try{
00074 s = new EndianIn( fname );
00075
00076
00077
00078
00079
00080 s->set_bigendian();
00081 filler = data = new unsigned char[256*256*4];
00082
00083 int skip_count = 0;
00084 do{
00085 byte_in = s->read_byte();
00086 skip_count++;
00087 }while( byte_in != 0x80 );
00088
00089
00090 do{
00091 byte_in = s->read_byte();
00092 skip_count++;
00093 }while( byte_in != 0x80 );
00094
00095
00096 do{
00097 byte_in = s->read_byte();
00098 skip_count++;
00099 }while( byte_in != 0x0 );
00100
00101
00102
00103
00104 for( i=0; i<16; i++ ){
00105 byte_in = s->read_byte();
00106
00107 skip_count++;
00108 }
00109
00110
00111
00112 for( i=0; i<256*256; i++ ){
00113 index = s->read_byte();
00114 *filler++ = color_table[index*4+0];
00115 *filler++ = color_table[index*4+1];
00116 *filler++ = color_table[index*4+2];
00117 }
00118 }catch( ... ){
00119 emsg( M_MAT, "Error reading texture %s: %d bytes missing", fname.c_str(), 256*256 - i );
00120 }
00121 s->close();
00122 dmsg( M_MAT, "%s\n", fname.c_str() );
00123
00124 glBindTexture ( GL_TEXTURE_2D, gl_texture_id );
00125 glPixelStorei ( GL_UNPACK_ALIGNMENT, 1 );
00126 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
00127 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
00128 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
00129 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
00130 # if !defined( USE_TINY_GL )
00131 glTexImage2D ( GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, data );
00132 # else
00133 glTexEnvi ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );
00134 glTexImage2D ( GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, data );
00135 # endif
00136 delete[] data;
00137 this->is_good = true;
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154 }
00155
00156
00157 };
00158 };
00159