Guide to Game Development/Theory/Graphical User Interfaces (GUI) and Heads-up-displays (HUD)
Appearance
In order to render a GUI or a HUD on top of the gameplay, then you need to clear the depth buffer. Every time you want a new layer of geometry, you'll need to clear the depth buffer to make sure that the layers don't interact with each other.
Here's some pseudocode of the drawing of the game, the HUD and the GUI.
Render(){
//Resetting from last frame
ClearScreen();
DepthBuffer.Clear();
SetProjectionMode(Projection);
DrawGameGeometry();
DepthBuffer.Clear();
SetProjectionMode(Orthographic);
DrawHUD();
if (isMenuOpen){
DepthBuffer.Clear();
//Let's say it's a 2D GUI, so going to leave it as orthographic
DrawGUI();
}
}