tga loading problems

my tga loader isn’t loading tga’s! grrr… if you could take a look at my loader and spot any errors that i might have missed that would help me out alot. Thanx!

void tga: efine(){
void tga::GenerateID(){

void tga::Bind(){

void tga::Filter(){

bool tga::Load(char *filename){
fstream file;
long x = 0;
unsigned char rgbSwitch;,ios::in | ios::binary);
	return false;
	file.seekg(2,ios::beg);*)&m_type,sizeof(unsigned char));
	if((m_type != 2) | | (m_type != 3)){
		return false;
		file.seekg(13,ios::cur);*)&m_Width,sizeof(short int));*)&m_Height,sizeof(short int));*)&m_bites,sizeof(unsigned char));
		m_channels = m_bites / 8;
		m_size = m_Width * m_Height;
		m_size *= m_channels;
		m_data = new unsigned char[m_size];*)&m_data,sizeof(unsigned char));

		while(x < m_size){
			rgbSwitch = m_data[x];
			m_data[x] = m_data[x + 2];
			m_data[x + 2] = rgbSwitch;
			x += m_channels;
		return true;

}*)&m_data,sizeof(unsigned char));

Your only reading in one byte of data.

i changed the line to:*)&m_data,sizeof(unsigned char)*m_size);
and it still doesnt work!

i think i found were the error could be happening:

if((m_type != 2) | | (m_type != 3)){
return false;

i dont think im putting in the right value for m_type. i want to skip the first 2 bytes of data of the header and get the type. i try to do this using the file.seekg(2,ios::beg); but i think that im using it wrong and putting wrong data into m_type. how can i skip data in a file/fix this problem?

You want to check the third byte in the file for either 2 or 3. 2 being black and white, 3 being true color, both being uncompressed. Check the spec for the other identifiers.


You should be doing a logical AND (&&) rather than a logical OR.

Old GLman

[This message has been edited by Old GLman (edited 12-12-2002).]

Yeah, try wotsi.


You are right about your diagnose of the m_type values not being the appropriate ones…
The 1, 2, 3, 4 are simply the number of channels (bytes) you are reading per pixel. But there is no such thing in the header of a TGA file. Instead, you read the number of bits per pixel (bpp). So, you would have 8, 16, 24, 32.
Well, where do these 1, 2, 3, 4 come from?
You divide the bpp, which is the third unsigned char in the header as you are reading, and divide it by 8. 8 is the number of bits in a byte.

You will also have more problems if the tga is compressed or palletted or so and so and more sos.

8 -> grayscale
16 -> Why use it? Palletted maybe?
24 -> RGB
32 -> RGBA

If you want you can use one I wrote.
Download the normal map generator from:
You can use and abuse it.

Good luck.

[This message has been edited by mancha (edited 12-15-2002).]