Why ofBeginShape complexity so bad?

Hi, I’m beginner.
I wrote some source to draw wave things.
I made it with perlinNoise and vertices… and ofBeginshapes.
but I’m not satisfied with the result.
when I tried to draw a third wave, I got some kind of lagged or bug.
below image shows problem which I’m suffering from.

following source is my source code.

vector<glm::vec2> v, v2, v3;
double fv=777, fv2=132, fv3=0;

void ofApp::setup() {

	ofSetFrameRate(60);
	ofSetWindowTitle("openFrameworks");
	//font.loadFont("BMHANNAPro.ttf", 90);
	//sound.load("Track28.mp3");

	ofBackground(239);
	sound.setSpeed(2.0);
	sound.setMultiPlay(true);
}

void ofApp::update() {
	ofSeedRandom(39);
	v.clear();

	v.push_back({ 0, ofGetHeight() });
	for (int i = 1; i < ofGetWidth()-1; i+=3)
	{
		v.push_back(glm::vec2(i, ofMap(ofNoise(i * 0.001, ofGetFrameNum()*0.00001,fv+=0.000001), 0, 1, 0, ofGetHeight())));
	}
	v.push_back({ ofGetWidth() - 1, ofGetHeight() });

	v2.clear();

	v2.push_back({ 0, ofGetHeight() });
	for (int i = 1; i < ofGetWidth()-1; i+=3)
	{
		v2.push_back(glm::vec2(i, ofMap(ofNoise(i * 0.001, ofGetFrameNum()*0.00001, fv2+=0.000001), 0, 1, 0, ofGetHeight())));
	}
	v2.push_back({ ofGetWidth() - 1, ofGetHeight()});

	v3.push_back({ 0, ofGetHeight() });
	for (int i = 1; i < ofGetWidth()-1; i+=3)
	{
		v3.push_back(glm::vec2(i, ofMap(ofNoise(i * 0.001, ofGetFrameNum()*0.00001, fv3+=0.000001), 0, 1, 0, ofGetHeight())));
	}
	v3.push_back({ ofGetWidth() - 1, ofGetHeight() });


}

//--------------------------------------------------------------
void ofApp::draw() {
	ofSetColor(0, 39, 255, 50);
	ofBeginShape();
	ofVertices(v);
	ofEndShape();

	ofSetColor(233, 233, 39,39);
	ofBeginShape();
	ofVertices(v2);
	ofEndShape();

	ofSetColor(0, 111, 100);
	ofBeginShape();
	//ofVertices(v3); // <--- problems
	ofEndShape();
}

//--------------------------------------------------------------
int main() {
	ofSetupOpenGL(1420, 960, OF_WINDOW);
	ofRunApp(new ofApp());
}

I think the source what I wrote, does not have serious time complexity. :cry:
how can I get more performance?

sorry for lack of English. thanks for reading.

Hi and welcome to the forum!

You are missing v3.clear() on update.
So you just keep adding more and more vertices. : )

There are other ways of drawing stuff in OF. Since you are starting, did you check the OFBook and the section onf Meshes?

1 Like

Thank you Hubris. I absolutely misunderstood openframeworks performance… : 0 … oops…
I’ll see OFBook Meshes section.
Thank you !!:grinning: