2

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?

  • What does FreeImage_GetPitch return? If it is negative, scanlines in memory are bottom-up. If it is positive, scanlines are top-down. I suggest you manually convert to a bitmap which OpenGL can accept. – strager Jan 15 '09 at 03:22

4 Answers4

4

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
  • 28,429
  • 12
  • 61
  • 81
  • 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 Jan 15 '09 at 08:32
  • @Frans Bouma: I think it's a fine choice if you consistently use the same format. If you're mixing & matching formats (with different top to bottom ordering), it could definitely be a headache. – Drew Hall Jan 15 '09 at 15:45
  • 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 Sep 04 '09 at 13:51
2

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
  • 8,259
  • 1
  • 27
  • 28
2

Might give FreeImage_FlipVertical() a try.

genpfault
  • 51,148
  • 11
  • 85
  • 139
2

Depending on your app, most professional games would flip their textures in their build process, not at load time.

gman
  • 100,619
  • 31
  • 269
  • 393