At the outset, i believe the problem is related to Depth Buffering. Try enabling z-buffering in by calling the following functions:
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
And also, do check if you are clearing the z-buffers along with the color buffers.
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);