Question

Since I have started learning about rendering to a texture I grew to understand that glCopyTexSubImage2D() will copy the designated portion of the screen upside down. I tried a couple of simple things that came to mind in order to prevent/work around this but couldn't find an elegant solution.

  • there are two problems with doing a ::glScalef(1.0f, -1.0f, 1.0f) before rendering the texture to the screen: 1, I have to do this every time I'm using the texture. 2, I'm mostly working with 2D graphics and have backface culling turned off for GL_BACKsides. As much as possible I'd love to save switching this on and off.

  • tried switching matrix mode to GL_TEXTURE and doing the ::glScalef(1.0f, -1.0f, 1.0f) transformation on capturing, but the results were the same. (I'm guessing the texture matrix only has an effect on glTexCoord calls?)

So, How can I fix the up-down directions of textures captured with glCopyTexSubImage2D?

Was it helpful?

Solution

What are you going to be using the texture images for? Actually trying to render them upside down would usually take more work than moving that code somewhere else.

If you're trying to use the image without exporting it, just flipping the texture coordinates wherever you're using the result would be the most efficient way.

If you're trying to export it, then you either want to flip them yourself, after rendering.

On a related note, if you are making a 2D game, why is backface culling turned on?

OTHER TIPS

If my understanding is correct, it depends on where your origin is. That function seems to assume your origin is in the bottom-left, whereas most 2D stuff assumes an origin of the top-left, which is why it seems upside down.

I suppose you could change the origin to the bottom-left, do the capture, then change the origin back to the top-left and render again before doing the swap. But that's a horrible solution since you're effectively rendering twice, but it might be fine if you don't plan to do it every frame.

Use glReadPixels() to copy to a buffer, flip the image, then use glTexImage2D() to write it back.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top