Search code examples
javaopengllwjgl

What is the value of z-coordinate in opengl


I have just started learning modern opengl using lwjgl 3. I am confused with the coordinate system of opengl.

I know that when you specify the width and height of the window the coordinates are mapped to that width and height.For example if screen width is 600 the coordinate[1,0] will be mapped to[600,0].

What I wanna know is what is the distance value of z Coordinate?


Solution

  • The z coordinate corresponds to depth. It's value is usually the fraction representing the distance of the fragment between the near plane and the far plane, as demonstrated here: The camera and its near and far planes. Clipped means that a fragment is not visible.

    The z/depth value is used mainly for depth testing, a process which makes objects that are behind other objects (specifically they must be occluded by them) culled. It is best described here (from learnopengl.com):

    OpenGL stores all its depth information in a z-buffer, also known as a depth buffer. GLFW automatically creates such a buffer for you (just like it has a color-buffer that stores the colors of the output image). The depth is stored within each fragment (as the fragment's z value) and whenever the fragment wants to output its color, OpenGL compares its depth values with the z-buffer and if the current fragment is behind the other fragment it is discarded, otherwise overwritten. This process is called depth testing and is done automatically by OpenGL.

    I highly recomend checking out learnopengl.com even if you are using LWJGL because the majority of what you can find there also applies to it.