views:

838

answers:

3

When i load an image via FreeImage, the bits are bottom to top. My GL code expects all images to be topdown. Whats the best way to flip the image when i copy the bits to the texture?

+1  A: 

I think it's wise to do an in-place flip using simple array arithmetic and 1 temporary longword value. (so flip per pixel, 4 bytes).

You could of course flip texture coords but that would be unwise IMHO, as you probably don't want to pollute your code with the info that the texture is upside down.

Frans Bouma
+1  A: 

Might give FreeImage_FlipVertical() a try.

genpfault
+1  A: 

You could use the texture matrix to effectively flip texcoords. I think this would work:

glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glScalef(1.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
Drew Hall
Isn't that a bad choice? I mean: you'll embed an aspect of a texture in the code, so when the texture data is supplied correctly, your code all of a sudden doesn't work anymore .
Frans Bouma
Drew Hall
Texture matrix is no longer in core OpenGL - having to constantly patch vertex shaders to flip texture coordinates is painful and certainly inefficient. Better consistenly flip once and for all the source geometry texture coordinates, or flip the texture at load time and be done.
rotoglup