• Advertisement

Archived

This topic is now archived and is closed to further replies.

TGA Loading??

This topic is 5415 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I''m building a TGA loader, but I have a BIG problem!! My code --> GLvoid CTextureTGA::LoadTGA(char* strFileName){ GLbyte TGAHeader[3] = {0}; FILE *fileTGA; if (!(fileTGA = fopen(strFileName, "rb"))) return; if (!(fread(TGAHeader, sizeof(GLbyte), 3, fileTGA))) return; if (TGAHeader[2] == 2) LoadUncompressedTGA(strFileName, fileTGA); else if (TGAHeader[2] == 10) return; else return; } GLvoid CTextureTGA::LoadUncompressedTGA(char *strFileName, FILE *fileTGA){ GLbyte TGAHeader[6]; fread(TGAHeader, sizeof(GLbyte), 6, fileTGA); } The first time it reads the TGA header alright (I think), but second time in the second function (LoadUncompressedTGA) it dosn''t read the header... It just gives me a array filled with zeros??? What''s wrong???

Share this post


Link to post
Share on other sites
Advertisement
hm i always thought the TGA headers are 12 bytes long
so why don t you load the 12 bytes all at once ?

your header should look like this

GLubyte TGAheader[12]={0,0,2,0,0,0,0,0,0,0,0,0};
and the width and so on are stored in another 6 byte chunk i think
so i think i have answered your question

load a 12 byte chunk and compare it with the TGAheader show above

if(memcmp!=0)
return;
and then read the other 6 bytes to get the width and the bits per pixel

Share this post


Link to post
Share on other sites
jepp... 12 bytes long header.
...and what is the first parameter to CTextureTGA::LoadUncompressedTGA for?

Share this post


Link to post
Share on other sites
Thx...

The problem is solved!! Yes the first parameter for LoadUncompressed() is a mistake...

By anyways - thx again!

Share this post


Link to post
Share on other sites

  • Advertisement