PuRe
PuRe

Reputation: 189

OpenGL FrameBuffer upside down and bottom right

So I'm making an engine which can use directx10,11 and opengl.

So far everything worked well. It can render an image in opengl and directx correctly and both look the same.

Now I added rendertargets. Within DirectX it works very well and there is no problem so far. But using OpenGL the texture which I draw before is upside down and on the bottom right of the rendertarget.

  Screenshot

Do you guys have an idea what the problem is? And why does it work without the rendertarget correctly?

If needed I can send some code. I just need to sort it first.

Upvotes: 4

Views: 5759

Answers (2)

PuRe
PuRe

Reputation: 189

set the glviewport correctly, which resulted in the rendertarget only being upside down but in the correct position. now I just changed the UV.y within the vertex shader to be -UV.y and its fixed.

Upvotes: 1

datenwolf
datenwolf

Reputation: 162164

OpenGL places the default origin of textures and thereby rendertargets in the bottom left. DirectX in the upper left. If you make the same assumptions about pixel layout it looks like the image is flipped. You can compensate this by applying a -1 scale on the projection matrix y-axis.

That the OpenGL image looks stretches is probably due to a wrong viewport being set when rendering to the FBO. Make sure that the viewport set with glViewport, when rendering to the FBO matches the dimensions and the target area in the render target.

Upvotes: 6

Related Questions