reversed lines with glCopyTexSubImage2D or with FBO


I’m doing render-to-texture and it works well, except that lines are reversed in the texture.

I’ve tried two methods :

  1. render in a PBuffer, and copy in the texture with glCopyTexSubImage2D
  2. using FBO and directly render in the texture
    These two methods have the same result : lines in the texture are reversed (the image in reversed along Y axis).

When I compare with my directX version, which is exactly the same code but for DirectX, the lines are correctly ordered.

Is there a way to change the order of lines with a function like glPixelStore ?

Thanks for your help,


OpenGL has its origin in the lower left corner.

You need to reverse the y in your glOrtho call.

You’re right : I just have to reverse Y in my projection matrix.
But, this projection matrix is exactly the same I use with DirectX, so I can’t change it (else it will reverse DX rendering too, and the problem won’t be solved).
Do you know another way to tell OpenGL the order I want to have for my lines ? With a state parameter function ?

Thanks a lot,


Create your own matrices and give them to opengl or d3d. This is easy to do. In the appendix of the redbook (available online) the opengl projection matrices are given. And you have the MSDN for the d3d matrices…

PS. If you’re wrapping opengl and d3d, I wouldn’t make an implementation detail like a projection matrix a passed parameter. Think of creating a virtual “ortho” function, where you can hide issues like this.

Thanks :slight_smile:
But I allready create my own matrices, and I give them to D3D and GL. These matrices are exactly the same, and it works very well for all the stuff, except for render-to-texture due to D3D and GL conventions about copying pixels in the texture.

That’s why I’m looking for a function which could change the order of writing lines in the texture.
Does this function exist ?