othographic and perspective projections interacting?


In my OpenGLES 2.0 app, I am drawing some cubes with a perspective projection. Then I draw some with an orthographic projection. The orthographic cube is always drawn on top of the perspective ones – why is that? Is there any way to get them to intersect? I am not sure what that would mean – I am just wondering how it all works. What happens to the depth information if you change the projection matrix between object draws?


if they map to the same z range, and depth testing is enabled they will intersect

Yeah, that’s not going to work. What actually gets stored on your render target for depth is a 0…1 value where 0 == near plane and 1 == far plane. The mapping between EYE-SPACE (“real world”) depth values and this 0…1 range is different between orthographic and perspective. For orthographic, it is a linear mapping. For perspective, it is a non-linear one.

While you could hack things to make them both use the same depth encoding with custom shaders and some extra glue code, it still wouldn’t “line up” because the mapping for EYE-SPACE X and Y (left/right and up/down dimensions) are different.

Best bet: just draw them with the same projection so the drawing makes intuitive sense. If you absolutely must use different projections, clear the depth buffer or disable depth testing before you render with the second one.