image display

I use Imlib Imlib_load_image(…) read image and glDrawPixels(…) write image to window. It’s strange that the image is always upside down. Did anybody has this experience and could help me to solve it?



In OpenGL, th origin is in the lower left corner, so you have to load your images so that the origin is not in the upper left corner (or any other corner).

I did set position of image at(0,0) glRasterPos2i(0,0)

and I also tried any position. All the display results are same: upside down

As I said, OpenGL assumes the origin of the image is in the lower left corner, not the upper left. This has nothing to do with where you place the raster position, but how the data is stored in memory after you have loaded the image.

Thanks bob,

I understand what you mean, but I still have no idea how to fix this problem.
Should I restore the image into a new array and use the window’s height substracts current y?

There are a few ways to do this. I believe you can use glPixelZoom and scale the image by -1 vertically, but then you must place the raster position where the upper left corner of the image is supposed to be. This will, sortof, flip the image two times; store it upside down, and then draw it upside down. I have not tried this method myself, I usually load the image correct in the first place to be compatible with OpenGL. If you have third party library to load files, you could create a new image and copy the old image to the new, but changing the order of the rows. Or if you have access to the source, modify it so you don’t have to make the second copy.

If you choose to flip the image in memory, you don’t have to do anything about the raster position.

Got it. Thanks bob!