openFrameworks
openFrameworks copied to clipboard
Drawing ofMesh with Vertex Colors is not cleared for next mesh draw without colors
Using the programmable renderer.
//--------------------------------------------------------------
void ofApp::draw(){
ofSetColor(255, 255, 255);
ofMesh boxMesh;
boxMesh.setMode(OF_PRIMITIVE_LINES);
float bsize = 120.f;
boxMesh.addVertex(glm::vec3(-bsize, -bsize, -bsize));
boxMesh.addVertex(glm::vec3(bsize, -bsize, -bsize));
boxMesh.addVertex(glm::vec3(bsize, bsize, bsize));
boxMesh.addVertex(glm::vec3(-bsize, bsize, bsize));
boxMesh.addColor(ofColor::red);
boxMesh.addColor(ofColor::yellow);
boxMesh.addColor(ofColor::green);
boxMesh.addColor(ofColor::blue);
boxMesh.addIndex(0);
boxMesh.addIndex(1);
//
boxMesh.addIndex(1);
boxMesh.addIndex(2);
//
boxMesh.addIndex(2);
boxMesh.addIndex(3);
//
boxMesh.addIndex(3);
boxMesh.addIndex(0);
ofPolyline circle;
circle.arc(glm::vec3(0.f, 0.0f, 0.0f), 120.f, 120.f, 0, 360, true );
ofPushMatrix(); {
ofTranslate( ofGetWidth()/2, ofGetHeight()/2 );
ofPushMatrix(); {
ofTranslate(180, 0, 0);
// boxMesh.drawWireframe();
boxMesh.draw();
} ofPopMatrix();
ofPushMatrix(); {
ofTranslate(-180, 0, 0);
ofSetColor( 100.0f, (sinf(ofGetElapsedTimef()) * 0.5f + 0.5f) * 255, 50.0 );
ofSetColor( ofColor::orange );
circle.draw();
} ofPopMatrix();
} ofPopMatrix();
}
The above code outputs the following image
Commenting out the boxMesh.addColor();
lines yields the following output