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).
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.
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…
The easiest way to represent a TGA header is as an array of 9 unsigned shorts. short[6] is width, short[7] is height; you can mask out the other values too from the different shorts if you care.
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: