Z buffer plays an important role to draw 3D objects. Z buffer( depth buffer) holds the depth of each pixel.
Consider two objects with different z values, and some portion of one object and some portion of one object overlap with other. When first object drawn, its corresponding z values( the distance between view point and object) are updated in z-buffer and the pixel values(RGB) are updated in color buffer of the current rendering context.
During rendering next object, before updating a pixel in color buffer, openGL will compare the distance of current pixel from view point with the z-value in z-buffer( depth buffer). OpenGL modifies color buffer and depth buffer only if z-value of current pixel is lower than the z value of corresponding location in z buffer. If the new pixel is close to the eye point, openGL places the new pixel’s color in color buffer and its depth buffer.
