the TGA loading chronicles...grrr

lately ive switched over from bitmaps to targas for the alpha value ability. But its been giving me grief and i cannot figure out why. (im using NeHes code) i got pictures i wanted, saved them as 256x256 tga’s in 24 bit color mode (no alpha) but the program cannot load them! WHY??? What might i be missing?

Thanks.

You probably saved the images in a compressed format and I don’t think that NeHe’s TGA loader has any support for compressed images.

Open them up in Paint Shop Pro and click Save As, select the TGA format and click the Options button. Make sure that Uncompressed is selected and save the image.

Jason A.
DelphiGL (http://delphigl.cfxweb.net)

[This message has been edited by jra101 (edited 05-29-2001).]

you’re awesome man. thanks. I swear there is not a day I don’t learn something.

Another skill, which might be even more useful than knowing about a specific checkbox in a specific program, is the habit of putting breakpoints in the code you’re running, and single-stepping through it to see where it’s going wrong.

Thats what I did, I looked at the nehe code, roughly understood it but couldn’t be bothered writing my own but greatly increased the functionality by adding a load of error checking and loads of different OpenGL options. Now it is great becuase if the texture is compressed it will warn, smae if it can’t be found etc. My own TGA saver doen’t work tyhough , The file is the correct size to the nearest byte but there is still something wrong with the header, can’t think what?
The moral of the story is take time to write some good error checking code with everything and it will save you loads of time in the long run.

Well and another aspect concerning compressed TGAs: its very easy to read them actually. Wrieting your own TGA loader is just a matter of 1 day, because its very good documented. Here is my sample code that reads compressed TGA files (this piece of code only reads the compressed image data, not the header)

CurrentPixel = 0;
// m_width and m_height is width and height of the image, respectively
while (CurrentPixel < m_width*m_height -1)
{
  ch_buf1 = s.ReadChar(); // this is the same as fread(&ch_buf1, 1, sizeof(char), f)
  if ((ch_buf1 & 128) == 128)
  {   // this is an rle packet
    char ch_buf2 = (ch_buf1 & 127) +1;   how many pixels are encoded using this packet
    if (!s.Read(buf1, m_pixelDepth/8, 1))
    {
      free(m_pixels);
      ErrorMsg("LTGA::LoadFromStream: reading data from file failed

");
return ERR_FILE_READ_ERR;
}
for (int i=CurrentPixel; i<CurrentPixel+ch_buf2; i++)
for (int j=0; j<m_pixelDepth/8; j++)
m_pixels[i*m_pixelDepth/8+j] = buf1[j];
CurrentPixel += ch_buf2;
}
else
{ // this is a raw packet
ch_buf2 = (ch_buf1 & 127) + 1;
if (!s.Read(buf1, m_pixelDepth/8*ch_buf2, 1))
{
free(m_pixels);
WarningMsg("LTGA::LoadFromStream: reading data from file failed
");
return ERR_FILE_READ_ERR;
}
for (int i=CurrentPixel; i<CurrentPixel+ch_buf2; i++)
for (int j=0; j<m_pixelDepth/8; j++)
m_pixels[i*m_pixelDepth/8+j] = buf1[(i-CurrentPixel)*m_pixelDepth/8+j];
CurrentPixel += ch_buf2;
}
}

Hope this helps,
-Lev