Mesh stange glitch

hello,

i am facing a strange glitch when i manipulate my mesh. I don’t know if it is an issue with normals, or maybe bad indices or whatever.

Do you have an idea about the symptoms ?

here i am creating the mesh :

mesh.enableColors();
mesh.enableIndices();
glPointSize(pointSize);
glDisable(GL_POINT_SMOOTH);

int width = scaledImage.getWidth();
int height = scaledImage.getHeight();
for (int y = 0; y < height; y++) {
    for (int x = 0; x < width; x++) {
        ofColor c = scaledImage.getColor(x, y);
        float brightness = ofMap(c.getBrightness(), 0, 255, -displacement, displacement);
        ofPoint p(x * MAP_SCALE, y * MAP_SCALE, brightness);
        mesh.addVertex(p);
        mesh.addColor(image.getColor(x * MAP_SCALE, y * MAP_SCALE));
    }
}

//add indices
for (int y = 0; y < height - 1; y++){
    for (int x=0; x < width - 1; x++){
        mesh.addIndex(x+y*width);               // 0
        mesh.addIndex((x+1)+y*width);           // 1
        mesh.addIndex(x+(y+1)*width);           // 10
        
        mesh.addIndex((x+1)+y*width);           // 1
        mesh.addIndex((x+1)+(y+1)*width);       // 11
        mesh.addIndex(x+(y+1)*width);           // 10
    }
}

And i draw it like that :

void ofApp::draw(){
    cam.begin();
    ofPushMatrix();
    ofTranslate(-ofGetWidth() / 2, -ofGetHeight() / 2);
    mesh.draw();
    ofPopMatrix();
    cam.end();
}

i found a solution :

ofEnableDepthTest();
mesh.draw();
ofDisableDepthTest();

by the way, i started using ofEnableDepthTest() in setup() but ended up with empty GUI panels… i don’t know if it is a bug or an expected behaviour.

that’s correct. you can’t draw something like a 2d gui composed by several layers all at the same z while depth testing is enabled.