0

I have drawn an image file with the GIMP and saved it as a .c file. Then I used the following in my OpenGL code to load the image onto the screen:

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

glRasterPos2i(x_disp, 0);
glDrawPixels(80, 80, GL_RGB, GL_UNSIGNED_BYTE, gimp_image.pixel_data);

However the image loaded appear flipped 180 degrees upside down. I wonder whether there is an option I can supply in OpenGL so that I can have the image rendered with the same orientation as in GIMP, with the top side up, and the left side on the left, perhaps with glPixelStore or some other OpenGL function call to specify how to unpack the pixels?

genpfault
  • 51,148
  • 11
  • 85
  • 139
John Goche
  • 689
  • 2
  • 12
  • 27

1 Answers1

2

OpenGL assumes image data in the lower left corner, whereas most image manipulation programs place it in the upper left corner.

Instead of glDrawPixels use a texture, then you can just flip texture coordinates. glDrawPixels is a extremly slow CPU-cycle sucker anyway and has been removed from OpenGL-3 and later. Just don't use it.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • Thank you for your reply. I have not studied textures yet (will do so now). If I use a texture can I use the file exported from the GIMP? How? Presumable I can then also draw the image sideways instead of just face on, which as far as I can see cannot be done with glDrawPixels. Thanks, John Goche – John Goche Nov 12 '11 at 20:43
  • @JohnGoche You can draw it in anyway you like, when using textures. It just depends on the texture coordinates you specify, which you will (or rather should) learn about as soon as you delve into texturing. – Christian Rau Nov 12 '11 at 21:12