Setting the Perspective projection matrix in Open GL (including OpenGL ES 2.0) has the following general format:
glm::mat4 perspective(float fovy, float aspect, float zNear, float zFar);
Notice the last two parameters; First one specifies zNear plane, which is the plane closer to the camera. The second one specifies zFar plane which is far from the camera.
It is common knowledge that, in OpenGL, things that are further, in other words "deeper into the screen", have negative Z axis. Why then all the OpenGL examples, that set perspective projection matrix (taken from reliable sources like OpenGL SuperBible and simmilar) look like the two above mentioned parameters (zNear, zFar) of Perspective projection funcion are swapped?
This example is taken from GLM(OpenGL Math) webiste:
glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.f);
You can see, that the zNear parameter is actually further from the camera, than zFar parameter, which is 100 points closer to the camera/viewer.
Can you provide easy to understand explanation, please? I it is not just one but all the examples, which pass zFar as higher positive value than zNear. Thanks.
In my code, when I set:
glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 1000.0f, -500.0f);
I assume my frustum being 1000 points long in z-positive direction and 500 points long in z-negative direction.
When I set things like this, I can see at least some object, although things are not perfect: for some reasons I see only objects positioned on negative z coordinates.
This might relate to my incorrect understanding of the perspective projection function.