Skip to main content
GameDev.net gamedev.net
🔒 Locked

TGA loading

Started by Fimbulvetr Mar 12, 2007 at 3:52 AM 4 replies 1.8k views
Original Post
Fimbulvetr
Fimbulvetr
Hey, Ummm... I want to load a TGA file with and draw it with OpenGL, how do I know if the file pixels are packed and what type are they? RGB, BGR? And what do I do if I have a color pallete or color map? Thanks.
Eitsch
Eitsch
there's a tutorial on nehe about tga loading (with and without RLE compression)

its allways BGR or BGRA depending on 24 or 32 bit.
AndyEsser
AndyEsser
TGA Loading is actually really easy. I can't remember exactly how many bytes it is but if you read in the first 'x' bytes, that's the header. It contains all kinds of information such as image width and height and also pixel depth (24-bit or 32-bit).

If it's 24-bit then you know that the following data after the header is in BGR format. If it's 32-bit then it's in BGRA format and you can use it accordingly.

As Eitsch said there's a tutorial by NeHe and also in the OpenGL Game Programming book.

If you're still stuck when I get home I'll post my code for loading TGA's.
songho
songho
I believe TGA stores the pixel data in BGR order only, no option for RGB order.
Here is the most used values of image type in TGA header;
Image Type
==========
2: Uncompressed BGR(A) image.
3: Uncompressed Grayscale image.
10(2+8): RLE compressed BGR(A) image.
11(3+8): RLE compressed Grayscale image.

Here is source/bin of my TGA loader/write and it draws the TGA image using glDrawPixels(). Use it as reference:
imageTga.zip
lc_overlord
lc_overlord
We at the nehe dev team decided early on that we where going to make TGA files as easy to load as possible, therefore we made a pretty good texture loading class for everyone to use, you can find this class within lesson05 of the beta test on the new lessons, a link for this can be found on the nehe forum.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.