Sign in to follow this  

TGA Loading

This topic is 3841 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

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)
{
	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;
		}
	}
}

Share this post


Link to post
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 this post


Link to post
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.

Thanks for your reply.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

This topic is 3841 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this