Archived

This topic is now archived and is closed to further replies.

Aggrix

Targa (upside-down)

Recommended Posts

I''m using the Targa loading code in "OpenGL Game Programming" and when I load the Targa, it is upside-down. I know I have to change the Y offset (something like that) and I looked at the specs and I know where the bytes are located. My question is, how do I go about changing the value of the byte so that the image appears downside-down? Thnx

Share this post


Link to post
Share on other sites
I have the same book, what program are u working on?



-----------------------------
"There are ones that say they can and there are those who actually do."

"...u can not learn programming in a class, you have to learn it on your own."

Share this post


Link to post
Share on other sites
Im working on a 2D game and I''m using the Targa Loader on Chapter 7. When I bind the texture, its upsidedown. The TexCoords are right, I just think it has something to do with the Y offset. I using Gimp to make my .tga''s

Any Ideas?

Share this post


Link to post
Share on other sites

Just trying to remeber off the top of my head - but aren''t
TGA''s stored upside down in the file ?

--- bottom of pic ---
data
--- top of pic ------

If so - the easiest way to load this is to just start
loading the data from the file to the bottom of the memory
array you have setup to the top.

Given a targa that is H pixels high by W pixels width
with a Pictch - P. Your DATA array and a PTR

you do:

OFFSET = P * H - 1
PTR = DATA + OFFSET

Load a line then subtract from OFFSET PITCH.

Sorry - trying to work in Pseudo code here as its easier.

MrF

Share this post


Link to post
Share on other sites
As I recall somewhere the TGA header there''s a a couple of bit that tell you which orientation the file is saved in. It could be anything (eg upside down, reading right to left).

If you are looking for a robust TGA loader then you should check out the TGA header information. It''ll be on the Net somewhere.

Share this post


Link to post
Share on other sites
It''s stored in the 17th byte of the header....

typedef struct _TGAHead
{
BYTE idLenght;
BYTE colormapType
BYTE imageType;
WORD CMapStart;
WORD CMapLenght;
BYTE CMapDepth;
WORD XOffset;
WORD YOffset;
WORD Width;
WORD Height;
BYTE pixelDepth
BYTE ImageDescript;
} TGAHead;

ImageDescriptor byte:
bits 0 -> 3: attribute bits per pixel (16 & 32 bit tga''s)
bits 4 -> 5: contain origin location
(when 4 & 5 are both 0, orign is lower left)
bits 6 -> 7: are unused and should be zero...

An easy test is
if ( (imageDescript) & (1 << 4)) HFlip ()
if ( (imageDescript) & (1 << 5)) VFlip ()


Hope this helps

Share this post


Link to post
Share on other sites