The depth test resolves this using a depth buffer.
Begin rendering with a color buffer cleared to white and a depth buffer cleared to “far.”