openframeworks / openframeworks/openFrameworks

Removing color from ofVboMesh has no effect on drawing

Open
#5,492 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

section-3D
Dominant language
C++
Stars
10.4k
Forks
2.6k
Avg merge
1d 21h
Merged PRs (30d)
9

Description

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(1,0,1,1));
mesh.addColor(ofFloatColor(1,0,0,1));
mesh.addColor(ofFloatColor(0,1,0,1));
mesh.addColor(ofFloatColor(0,0,1,1));
}

//--------------------------------------------------------------
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.
b816a8049f629a2d8f16a29c1c968471f50b16db

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.
ce609a48875283804d2d95d82c2a8eef43b9259f

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

it seems the vbo is not being refreshed when ofVboMesh's color vector is changed through remove.

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) {}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied ofApp reproduction and compare ofVboMesh with the working ofMesh behavior, focusing on removeColor, setColor, and draw. Verify that removing colors refreshes the VBO data and that drawing reflects each removal before the color vector is empty.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
computer-graphics
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.