## Recommended Posts

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.


texture->imageData	= (GLubyte *)malloc(tga.imageSize);

while(pixel < tga.imageSize)
{
if( byte < 128)
{
byte++;
// these are the 1:1 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;
}
}
else
{
byte -= 127;
// 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;
}
}
}



##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
Was calculating the image buffer size wrong.

Was using bit depth instead of bytes per pixel.

Thanks again.

##### Share on other sites
Is still breaking but found the main problem with the image loading.

#pragma pack(push) /* push current alignment to stack */
#pragma pack(1) /* set alignment to 1 byte boundary */

tga structure

#pragma pack(pop)

Needed the pragma's to byte align.

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627662
• Total Posts
2978515

• 10
• 10
• 12
• 22
• 13