This is because openGL uses a right handed coordinate system [...]
No. OpenGL's default coordinate system which you are using when:
- you do not modify the matrix stacks (when working with the fixed-function pipeline)
- or when you use the identity matrix/transformation or no transformation at all (when you use shaders)
is the left-handed clip space/coordinate system. As you said correctly, though, its +Z axis points into the screen, away from the user.
This clip space displays vertices for which their x, y and z coordinates divided by their w coordinate (in your case probably just 1) is >= -1 and <= +1. See the OpenGL specification
at chapter 13.5. "Primitive Clipping".
You probably wonder why the quad does not show, when indeed the inequality is satisfied with z=+1. This seems to be because of floating-point rounding errors when using shaders. Rendering at z=+0.9999999f (which is just 1.0f - Math.ulp(1.0f)
, so the largest representable IEEE-754 32-bit floating-point value below 1.0f) does show the quad.
When you used the fixed-function pipeline, the quad at z=+1 would show. At least it does for me on Nvidia.
Also, glDepthRange(0.1, 100) does not do what you probably wanted it to do. It does not change the z-range of the clip space to be between 0.1 and 100, so that you could have rendered a quad at any z value within that range. No, this function only changes how the computed z value in the normalized device coordinate space - which is _always_ within [-1..+1] and is just the clip space after "perspective divide" - is translated to the window coordinates depth value written to the depth buffer.
And you should also read the documentation of that function, which states that any two arguments given to it will be clamped to [0..+1] before being effective. This is because the depth buffer can only store values within that range, max.
In order for you to render quads at different z values, you would need to change your coordinate system away from clip space into some other desired space, by applying some transformations in your shader, for example via a matrix.