TGA loading appear with wrong colour and flipped!

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?

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!

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.

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


// ...

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