To use the depth test, enable it during initialization.
And clear the depth buffer along with the color buffer during rendering.
If necessary, depth writes disables separately from depth tests.
The Depth Test is used in almost every GL application. Only the most trivial of demonstrations overlook it.