PDA

View Full Version : TGA loading appear with wrong colour and flipped!



clocKwize
05-29-2010, 04:53 PM
Hi everyone,

I'm just starting out with OGL, I've managed to get a quad displaying with a texture loaded from a TGA file but the image is flipped vertically and the colours are wrong, but not in a really obvious way... Notice the ordering of color in the rainbow fade? http://img205.imageshack.us/img205/8256/screenshot20100530at005.png

I'd post the code but I'm guessing that this is a common issue and people will be able to advise without it.. Please let me know and I'll post it.

Thanks for your help!

trinitrotoluene
05-29-2010, 07:11 PM
The image is flipped vertically because the coordinate in pixel (0,0) for OpenGL is bottom left, but for your image, it is top left. So when you begin to fill your array, start with the bottom of your image (0,image_height-1).

The color is wrong maybe because your TGA image is BGR encoded and OpenGL expect RGB order so try to swap the blue and red component to see what happen.

David_pb
05-31-2010, 09:43 AM
For the flipped v-Coords. It may also be possible that the image data is stored that way in your targa file. The format supports stuff like that, what you could do is to check the origin-value in the description field of the tga info structure:



#define TGA_ORIGIN_MASK 0x30

#define TGA_ORIG_LOWER_LEFT 0
#define TGA_ORIG_LOWER_RIGHT 1
#define TGA_ORIG_UPPER_LEFT 2
#define TGA_ORIG_UPPER_RIGHT 3

// ...

switch(header.description & TGA_ORIGIN_MASK) {
// handle cases...
}