TGA loading...

I need a sample code of TGA loading to Visual Studio 6.0, I’v tried many codes before and none of them are working.
Please help me!

type “opengl tga loading code” into google
i also have code on my site (profile)

are you looking to add tga images as resources to be included in the exe image or just run time loading?

if the former, I have no idea, so when you find out let us all know

if the later, nehe nehe nehe nehe nehe nehe nehe nehe nehe nehe nehe nehe NEHE

( i know everyone makes references to this site, but in reality, I think everyone should at least browse all those tutorials as soon as they hear about them. would save a lot of repetative posts )

Dave

hum, this an advanced opengl coding forum … you should post this topic on the beginner forum …

Arath

Try this other thread .

-Jason

lpVoid,

For putting a TGA into an executable as a resource, you can just include it as a custom resource in VC++. To access the data, you use FindResource to get a handle to the resource, Then LoadResource to load the resource, then LockResource to get an LPVOID pointer to the actual data. You can then just read from that data the same as if you had read in a full file before parsing the TGA header, etc…

interesting…

you know, I’ve been using VC++ since 4.something and I still don’t know how to use all of it’s features. I’ve just gotten used to the fact that it’s been easier to do something by hand than getting it working in the IDE. Microsoft makes me lazy, complacent, and unmotivated. Thanks for the eye-opener…

Dave

typedef struct
TargaHeader {
BYTE IDLength;
BYTE ColormapType;
BYTE ImageType;
BYTE ColormapSpecification[5];
WORD XOrigin;
WORD YOrigin;
WORD ImageWidth;
WORD ImageHeight;
BYTE PixelDepth;
BYTE ImageDescriptor;
} tga_header;

This is the header of a .tga file. If you work with truecolor images exported with photoshop, 3DsMax or a similar program, focus only on those variables:

PixelDepth: 8/16/24/32
ImageWidth, ImageHeigth.

Ok. If you want to load a .tga:

// Open the .tga file for read
FILE* tgafile = fopen(“some.tga”,“rb”);

// Read the header
fread (&tga_header, sizeof(tga_header), 1, tgafile);

The remaining data is the pixel data (again, for truecolor images), so we must determine if it’s 16,24 or 32 bits, create a buffer and then copy the pixel data to that buffer…
the buffer must be of size (imageWimageH(depth>>3))

fread (pixelBuffer, sizeof(pixelBuffer), 1, tgafile);

** Note that the pixel components are arranged as ARGB data (or RGB on 24 bit)

And that’s it… if you want to read a pixel, you could do something like this:
(I assume 32 bits data and pixelBuffer an array of DWORDs)

A = (BYTE) (pixelBuffer[0] >> 24) & 0xFF;
R = (BYTE) (pixelBuffer[0] >> 16) & 0xFF;
G = (BYTE) (pixelBuffer[0] >> 8) & 0xFF;
B = (BYTE) pixelBuffer[0] & 0xFF;

Sorry if you’re looking for a complete .tga reader, I just think that this format is very easy to read and I wanted to show you that…

  • Royconejo.

[This message has been edited by royconejo (edited 04-08-2001).]