Removing color from ofVboMesh has no effect on drawing

I tried to remove color from ofVboMesh’s color array and it seems to have no effect on drawing whereas if I use ofMesh, it works correctly.

Here’s a test code below.

in ofApp.h

ofVboMesh mesh; //ofMesh works correctly but not ofVboMesh.

in ofApp.cpp

//--------------------------------------------------------------
void ofApp::setup(){

mesh.addVertex(ofVec3f(0,0,0));
mesh.addVertex(ofVec3f(100,0,0));
mesh.addVertex(ofVec3f(100,100,0));
mesh.addVertex(ofVec3f(0,100,0));

mesh.addIndex(0);
mesh.addIndex(1);
mesh.addIndex(3);
mesh.addIndex(1);
mesh.addIndex(2);
mesh.addIndex(3);

mesh.addColor(ofFloatColor(255,0,255,255));
mesh.addColor(ofFloatColor(255,0,0,255));
mesh.addColor(ofFloatColor(0,255,0,255));
mesh.addColor(ofFloatColor(0,0,255,255));

}

//--------------------------------------------------------------
void ofApp::update(){

}

//--------------------------------------------------------------
void ofApp::draw(){

ofTranslate(50, 50);
mesh.draw();

}

//--------------------------------------------------------------
void ofApp::keyPressed(int key){

if (key == OF_KEY_RETURN) {
    
    if (mesh.getNumColors()) {
        
        size_t lastIndex = mesh.getNumColors()-1;
        mesh.setColor(lastIndex, ofFloatColor(0,0,0,0));
        mesh.removeColor(lastIndex);
    }
    cout << "numColors : " << mesh.getNumColors() << endl;
}

}

And this is the result you get when you run the code.

And when you press the ‘return’ key, last color should be removed from the color vector. For example if you press the key twice, the result should look as below.

But if I use ofVboMesh, removing color from vector doesn’t have any effect on the drawing until the vector gets emptied.

Is this a bug or is it natural behavior of ofVboMesh?
Would there be any trick to fix this?

Also, I think it would make more sense to automatically make the color cleared to ofFloatColor(0,0,0,0) as soon as color gets removed from the vector.

Meaning, the code should still work even without “mesh.setColor(lastIndex, ofFloatColor(0,0,0,0));” in ofApp::keyPressed(int key) {}

that sounds like a bug, like the vbo is not being refreshed when the mesh is changed through remove, can you open an issue?

in any case the behaviour of this is undefined since the number of vertices and colors in this case should always be the same

1 Like

I just did. Thank you @arturo!

https://github.com/openframeworks/openFrameworks/issues/5492