Suppose I load an array of bytes as RGB from a given file.
I've read that OpenGL likes to store its textures "reversed", and I've seen demo programs storing their images flipped upside down.
So in my program, must I reverse the loaded RGB array byte by byte, or line by line?
That's because the Bitmap(.bmp) format stores it's lines upside-down. I'm not sure who came up with that, but it's a file-format thing. So well, yes, you must do it if you use your own .bmp loader. You can, however, use one which has already been written which "upside-downs" the image for you. Again, it's only a .bmp thing. OpenGL works by default on non-flipped images.
Here's a little trick: If you don't want to change your .bmp loader, you can tell OpenGL to flip your image for you:
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glScalef(1.0f, -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
That's what I meant with "by default". You can turn OpenGL upside-down if you want to. However, this only works if you only load .bmp files. Other file formats store their lines properly. Therefore, I prefer the first approach - use a real .bmp loader.
Just to be clear: IF you load .bmp files, you MUST flip the image either by hand before sending it to OpenGL (which most .bmp loaders do), OR send the unflipped image to OpenGL and add the above code before your rendering code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With