FINALLY FIXED example2. Just needed to set GL_DEPTH_BUFFER_BIT in glClear().