texture->imageData = (GLubyte *)malloc(tga.imageSize);
while(pixel < tga.imageSize)
{
fread(&byte, 1, 1, fTGA);
if( byte < 128)
{
byte++;
// these are the 1:1 pixels
for(ix = 0; ix < byte; ix++)
{
fread(&RGBA, 1, tga.pixelBytes, fTGA);
texture->imageData[pixel ] = RGBA[2];
texture->imageData[pixel + 1 ] = RGBA[1];
texture->imageData[pixel + 2 ] = RGBA[0];
if(tga.pixelBytes == 4)
{
texture->imageData[pixel + 3] = RGBA[3];
}
pixel+=tga.pixelBytes;
}
}
else
{
byte -= 127;
fread(&RGBA, 1, tga.pixelBytes, fTGA);
// these are the compressed pixels
for(ix = 0; ix < byte; ix++)
{
texture->imageData[pixel ] = RGBA[2];
texture->imageData[pixel + 1 ] = RGBA[1];
texture->imageData[pixel + 2 ] = RGBA[0];
if(tga.pixelBytes == 4)
{
texture->imageData[pixel + 3] = RGBA[3];
}
pixel+=tga.pixelBytes;
}
}
}
TGA Loading
If anyone can offer suggestions why this code isn't working I would be greatfull.
Here's what's happening. The TGA loads really nice for everything but the "bottom row" of the TGA. My code is similar to others I've seen, however, when I make my tga with Corel Paint Shop Pro Photo XI it doesn't load correctly with my code but works fine with the others. Any Ideas? I've been working at this for 3 days now.
Your code looks fine to me. If your problem is just the last row, then I believe the bug is not around here.
Verify the following:
1. Is the tga.imageSize correct when you enter the while loop?
2. Is the "pixel" value correct when you exit the while loop?
3. Check the last pixel - the bottom right pixel. Simply look at the texture->imageData buffer, in pixel-3, pixel-2 and pixel-1 - and check that the value of that pixel is the same as it shows in the real picture.
If all these tests are ok, then the bug is somewhere else. Look at your drawing code for possible answers.
Verify the following:
1. Is the tga.imageSize correct when you enter the while loop?
2. Is the "pixel" value correct when you exit the while loop?
3. Check the last pixel - the bottom right pixel. Simply look at the texture->imageData buffer, in pixel-3, pixel-2 and pixel-1 - and check that the value of that pixel is the same as it shows in the real picture.
If all these tests are ok, then the bug is somewhere else. Look at your drawing code for possible answers.
Pixel value seemed a bit larger than it should be upon exit.
Used the debugger to make the tga.imageSize smaller so the loop would exit earlier and that didn't remedy the situation.
When I display the quad (using OGL), I'm using 3D vertexes to map the texture. This is the only differences I noticed between mine and some other TGA loaders.
Perhaps it's the way I have OGL set up to display the quads. Will look a little further.
Thanks for your reply.
Used the debugger to make the tga.imageSize smaller so the loop would exit earlier and that didn't remedy the situation.
When I display the quad (using OGL), I'm using 3D vertexes to map the texture. This is the only differences I noticed between mine and some other TGA loaders.
Perhaps it's the way I have OGL set up to display the quads. Will look a little further.
Thanks for your reply.
Was calculating the image buffer size wrong.
Was using bit depth instead of bytes per pixel.
Thanks again.
Was using bit depth instead of bytes per pixel.
Thanks again.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement