When loading a texture in OpenGL, how do I specify the origin of the data I am loading?
For example, how would I load a Targa that has it's origin at the top left instead of the bottom left of the image?
You can't, at least not directly. The origin of textures in OpenGL is the lower-left corner. You need to vertically flip your image if it doesn't match this coordinate system. So it's really an image processing problem, not an OpenGL problem.
(Alternatively, you can flip all your texture coordinates that refer to the image.)
As a first solution, you could just change the coordinates accordingly yourself when calling
To flip your texture origin you could easily flip your coordinate system. A naive solution would be
That's rather hacky and will not work for complex situations (without hacking even more.) The correct way to go in old OpenGL is the
Another approach to this problem (the correct one IMHO, fully-compatible with modern OGL) is processing the image in shaders. It's very simple: your new
You should flip the image data before uploading it to the GPU. Depending on the image library you are using it might be possible to flip the images already when loading without extra effort.
Don't try to workaround this by flipping texture coordinates or altering texture matrices. Those are not general solutions and only pollutes your code here and there. They are also incompatible with Framebuffer objects, since those expect the texture coordinates to be without any flipping.
Note that cube maps should not be flipped before uploading them. Those can be used directly as they are.