 <p>I found a solution, so I'll post it here for the public:</p> <ol> <li><p>In the <code>init()</code> function, need to add:</p> <p><code>glEnable(GL_DEPTH_TEST);</code></p></li> <li><p>In the painting function, in the <code>glClear()</code> call, add <code>" | GL_DEPTH_BUFFER_BIT"</code>:</p> <p><code>glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);</code></p></li> <li><p>In the <code>main()</code> function, in the<code>glutInitDisplayMode()</code> call, add <code>" | GLUT_DEPTH"</code>:</p> <p><code>glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);</code></p></li> </ol>