30 ifstream file( filename.c_str(), ios::binary );
36 BYTE unCompressHeader[12] = {0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0};
37 file.read( (
char *)tgaHeader,
sizeof(tgaHeader) );
40 if( memcmp( unCompressHeader, tgaHeader,
sizeof(unCompressHeader) ) != 0 )
45 file.read( (
char *)header,
sizeof(header) );
51 setWidth( header[1] * 256 + header[0] );
52 setHeight( header[3] * 256 + header[2] );
53 setBPP( header[4] / 8 );
57 BYTE *image =
new BYTE[
sizeof(BYTE) * getWidth() * getHeight() * getBPP()];
59 file.read( (
char *)image,
sizeof(BYTE)*getWidth() * getHeight() * getBPP());
68 setFormat( GL_BGR_EXT );
91 fopen_s( &file, filename.c_str(),
"wb" );
98 unsigned char unCompressHeader[12] = {0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0};
99 unsigned char header[6];
100 header[0] = getWidth() % 256;
101 header[1] = getWidth() / 256;
102 header[2] = getHeight() % 256;
103 header[3] = getHeight() / 256;
104 header[4] = 8 * getBPP();
106 fwrite( unCompressHeader,
sizeof(unCompressHeader), 1, file );
107 fwrite( header,
sizeof(header), 1, file );
111 if( getFormat() == GL_RGB ) {
113 setFormat( GL_BGR_EXT );
119 fwrite( getImage(), getWidth() * getHeight() * getBPP(), 1, file );