I wrote my TGA engine based off of nehe’s lesson. I also have a BSP engine. So I extracted the Quake III pk3 files and had it read a BSP. When ever it reads a BSP it reads most of the images but a few of the TGA’s will not load with my TGA code. The error is it cannt find out if its an uncompressed or compressed True Color TGA. The type of TGA is an uncompressed True Color TGA, which my TGA engine supports. nehe’s code reads it but it looks like when you get a bad singal on your TV(black and white with lines).
Here is my code and some of the images it couldnt load. They loaded fine in GIMP.
I don’t have time at the moment to look at your source in detail but a quick glance reveals that your tga file header is wrong.
First of all, use:
Otherwise you will have alignment problems.
Secondly, the TGA file format can be found on the web. The file name I have is TGA_FFS.RTF A quick search found this copy: http://honors.tntech.edu/~will/fileformat.virtualave.net/graphics/tga_ffs/tga_ffs.rtf
It goes over the file format quite nicely and (in my opinion) alot quicker for you to read that than for me to post a bunch of corrections. It covers the TGA Version 2.0 specs so you could later expand your reader if you want to.
Originally posted by JotDot:
There you go, you do learn something every day. That explains why the packing in my TGA header was screwy when I was trying to write it out as a single block. Thx JotDot…
I just stuffed the images you provided the link to through the TGA code I use and they worked OK. The code I use came from Texture Mapping Part 4
The easiest way to represent a TGA header is as an array of 9 unsigned shorts. short is width, short is height; you can mask out the other values too from the different shorts if you care.
It seems it will just be easyer to just redo the code based off the gametutorials code.
…or the GLFW TGA loader…
Anyway. My advise is to NEVER load/save structs, or arrays of elements other than 8 bits. You will almost always get problems with compiler/architecture dependencies such as alginment and endianity. I usually do it the “hard” way by writing dedicated routines for reading structures. In GLFW this is what I do:
// Read TGA file header from file
fread( buf, 18, 1, f );
// Interpret header (endian independent parsing)
h->idlen = (int) buf;
h->cmaptype = (int) buf;
h->imagetype = (int) buf;
h->cmapfirstidx = (int) buf | (((int) buf) << 8);
h->cmaplen = (int) buf | (((int) buf) << 8);
h->cmapentrysize = (int) buf;
h->xorigin = (int) buf | (((int) buf) << 8);
h->yorigin = (int) buf | (((int) buf) << 8);
h->width = (int) buf | (((int) buf) << 8);
h->height = (int) buf | (((int) buf) << 8);
h->bitsperpixel = (int) buf;
h->imageinfo = (int) buf;
// Extract alphabits and origin information
h->_alphabits = (int) (h->imageinfo & _TGA_IMAGEINFO_ALPHA_MASK) >>
h->_origin = (int) (h->imageinfo & _TGA_IMAGEINFO_ORIGIN_MASK) >>
…at a glance.