hiding surface behind


I am drawing 3-D cubes by drawing their surfaces composed of polygons. But when rotating, some surfaces behind can also be seen. How do I hide surfaces behind? Thanks for your help.


Do you have a depth buffer? Did you turn on depth test? It is diabled by default.

BTW, this is a beginner’s question.