To improve my understanding of OpenGL and 3D I am trying to implement a simple rendering pipeline running only on the CPU. Where it makes sense, I'm trying to use the same standards as OpenGL. For example, I'm using a right handed coordinate system like OpenGL. As it often happens when learning something new, I've now run into a question I cannot find an answer to. If something in the following doesn't make sense, please forgive and correct me.
In clip space (the coordinate you give to gl_Position
in your vertex shader), negative Z is away from the user. But in the depth buffer, positive Z is away (if you're using the default depth settings).
One answer to this question suggests that the flip is due to the projection transformation. But I made a little experiment (based on WebGL/OpenGL ES) that suggests the opposite: In clip space, Z is pointing away from the user even if you don't use a projection transformation.
So at some point, after you've handed it your gl_Position
, OpenGL flips the Z coordinate. When and how is that?
My guess is that it is in the viewport transform but I haven't been able to find documentation that supports this.