openFrameworks icon indicating copy to clipboard operation
openFrameworks copied to clipboard

Drawing ofMesh with Vertex Colors is not cleared for next mesh draw without colors

Open NickHardeman opened this issue 4 weeks ago • 0 comments

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 Screenshot 2024-06-04 at 9 20 54 PM

Commenting out the boxMesh.addColor(); lines yields the following output Screenshot 2024-06-04 at 9 21 08 PM

NickHardeman avatar Jun 05 '24 01:06 NickHardeman