Depth Test doesn't work with Vertex Transform

Hello!
I have an ofMesh and I’m displacing the vertex positions with a vertex shader. The problem is, z-fighting occurs.

If I call ofEnableDepthTest(), the mesh doesn’t render at all.

This problem doesn’t occur if I load the vertex positions on the CPU with mesh.getVertices() and update them there, but this takes a performance hit. Does anyone know why?

My end goal is to have the mesh vertices be displaced by a height map.

Thanks!

Sorry, I’m dumb. I found the problem after a while looking.

It didn’t render because I was drawing the mesh in an ofFbo, meaning I needed to clear the depth buffer every render frame. Mentioned in this thread.

Correct order:

fbo.begin();
glClear(GL_DEPTH_BUFFER_BIT);
ofEnableDepthTest();
cam.begin();
shader.begin();
mesh.draw();
shader.end();
cam.end();
ofDisableDepthTest();
fbo.end();