Advertisement

Creating Targa Files in PSP 8.0?

Started by August 04, 2004 12:33 AM
2 comments, last by python_regious 20 years, 3 months ago
I'm trying to create some Targa files for a project I'm currently working on, but I can't seem to get them to work using NeHe's Targa image loader from lesson 24("Initialization Failed." error). Looking around a little bit on the Internet has yielded no help either. Can anybody tell or point me in the direction of the proper way to create 32-bit Targa files using Paint Shop Pro 8.0? Or a compatible loader? The code that creates the "Initialization Failed." error is ...

if(	file==NULL ||fread(TGAcompare,1,sizeof(TGAcompare),file)!=sizeof(TGAcompare) ||	memcmp(TGAheader,TGAcompare,sizeof(TGAheader))!=0 ||	fread(header,1,sizeof(header),file)!=sizeof(header))
{
     if (file == NULL)
          return false;
     else    // <======== this else statement executes, resulting in a  value of false being returned
     {
	fclose(file);				
	return false;					
     }
}

Edited several times to make Targa code more readable



Go here and download the TGA specification (the one from Truevision).

I assume the problem is the memcmp function, which returns non-zero. This is because you're comparing the actual header with a pre-defined header, a pre-defined header which does not work with TGAs exported from PSP8. PSP8 writes some extra information, which is not handled by your loader.

The files written by PSP8 are correct according to the specification, so you just have to make a more generic loader to handle the extra information.
Advertisement
Also remember to check if the image is compressed or not.
The NeHe TGA loader is horrific. Do as other people have said and grab the specification and write your own.
If at first you don't succeed, redefine success.

This topic is closed to new replies.

Advertisement