"z buffer"(depth buffer?) does not appear to work as described in an XNA tutorial

I am creating the terrain from this tutorial here With a Monogame 3.2 WindowsGL project
and the last section (before the second photo) describes how to use the ‘Z Buffer’(depth buffer?) for XNA but when running the code it does not appear to do anything with or without the changes.
The tutorial has the plain code used for the example there on the website at the bottom if you’d like to give it a test.

This is what’s happening after a small amount of rotation
The image because I cant use the normal image linking

This is my first foray into 3d content so I’m not sure which of the elements of the program is causing it but I can assume its that the GraphicsDevice.Clear doesn’t use the depth float value properly (or not like I said I’m not an expert XD).
If its one of those two are there any manual work arounds?

Things to try…

  • Is a depth buffer being created?
  • Is the GraphicsDevice.DepthStencilState being set?
  • Is the custom effect not working correctly?

EDIT: it appears you need to manually set both

GraphicsDevice.DepthStencilState.DepthBufferEnable = true;
GraphicsDevice.DepthStencilState.DepthBufferWriteEnable = true;

In the draw method and that seems to have fixed it. Not sure if thats supposed to happen (probably not considering you didn’t have to in xna??)
Thanks for the pointers!

That isn’t the correct way to do that and will get you into trouble. Instead just do this:

GraphicsDevice.DepthStencilState = DepthStencilState.Default;

That is the correct way to do what you want.

ah thanks, saves me coming back when it does get me in trouble XD