How can I switch correctly between perspective and ortho?

I’m working on a 3D game but also have to render some status in 2D. So first I turn on the 3D:

        camera(WIDTH/2, HEIGHT/2 - camAngle*1.3, 950 - camAngle/3, WIDTH/2, HEIGHT/2, 0, 0, 1, 0)
        perspective(45, WIDTH/HEIGHT, 0.1, 2000)

Then I render the scene, and finally want to switch back to 2D mode:


But it doesnt work, drawing after the ortho does not show anything on the screen. so the matrices must be wrong. Documentation says, that ortho() sets it back to standard. So I have choosen a camera which should work. the distance is not that important in ortho, so I have choosen 1.

Any idea, what I missed? I think I could maybe solve it by reading the matrices at start of draw and set them again in my second render pass, but on the other hand i would like to know whats wrong with my code.

Try this when you want to switch back to ortho:

viewMatrix( matrix() )

This resets the viewMatrix to the identity (default). The camera() function is just a convenient way of manipulating the view matrix in terms of a camera position and look-at point.

Thanks @Simeon, works perfectly :slight_smile:

I have one question left: What happens to the depth buffer when switching? With OpenGL I would disable the depth test to render the overlays without z-problems. I had no problems now, so do you delete it when switching to ortho?