Targa (upside-down)

Started by
4 comments, last by Aggrix 22 years, 1 month ago
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
Advertisement
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."

-----------------------------"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."
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?

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
MrF.--Code..reboot..code..reboot..sigh!
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.
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

This topic is closed to new replies.

Advertisement