While i am new to opengl and rarly ask for help i think a need some clarification regarding Z-axis, depth-test and GLM:ortho. Been strugling with this for a week or two and everything have from the start been "reversed".
So im using:
glDepthFunc(GL_LESS);
glDepthRange(0.0f, 1.0f);
glm::ortho(0.0f, 800, 0.0f, 800), 0.0f, 1.0f);
- Z-axis is Y / 800(height), objects with Y = 20 is behind Y = 10.
Okej, so everything should add up, small Z is in front and big in the back, but no. Everything is the opposite.
According to this thread and default value of glDepthFunc/glClearDepth, everything should be in left-hand-coordinates when MVP is provided to a shader.
So while i read the linked thread i discovered that glm::ortho SHOULD convert right-hand-coordinates (because apperently thats what everybody is using in examples) to left-hand-coordinates. Sound greats, so why does it not work?
When you look into the library of GLM you will find glm::ortho, glm::orthoLH and glm::orthoRH which sounds very intressting. If i use glm::orthoLH everything adds up and works perfect, since it converts all my coordinates to left-hand. So why does glm::ortho not do this for me?
Apperently there is a settings for this when you compile the GLM-library. The GLM_COORDINATE_SYSTEM controls if the system is going to have glm::orthoLH or glm::orthoRH as default when glm::ortho is called. And to my surprise, glm::orthoLH is NOT default.
If you look in the source code of GLM you will find these lines,
#define GLM_LEFT_HANDED 0x00000001 // For DirectX, Metal, Vulkan
#define GLM_RIGHT_HANDED 0x00000002 // For OpenGL, default in GLM
#ifdef GLM_FORCE_LEFT_HANDED
# define GLM_COORDINATE_SYSTEM GLM_LEFT_HANDED
#else
# define GLM_COORDINATE_SYSTEM GLM_RIGHT_HANDED
#endif
OpenGL is right-handed and do not need to convert ortho to left-handed?
So my questions are,
- Why does GLM think OpenGL is right-handed?
- Is there any case where OpenGL acually want MVP as right-handed while processing shaders?
Please correct me if this doesnt make any sense. im confused too :)