Archived

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

OleKaiwalker

TGA Loading??

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
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