Fastest way to render quads


Im trying to create a 50x50 grid of quads and animate them with ofNoise(). <-- this is a picture of what i’m doing

And this is my code: here i setup a grid

for (int y=0; y<50; y++) {
for (int x=0; x<50; x++) {
w[x+y50] = xsize+ofNoise(x0.1, y0.1, ofGetFrameNum() / 3.0)30;
50] = ysize+ofNoise(x0.1, y*0.1, ofGetFrameNum() / 3.0)30;
50] = 0;

and here i draw the rectangles:

for (int y=0; y<49; y++) {
for (int x=0; x<49; x++) {
ofSetColor(120, ofRandom(160), 130);
ofVertex(w[x+y50], h[x+y50], d[x+y50]);
50], h[x+1+y50], d[x+1+y50]);
ofVertex(w[x+1+(y+1)*50], h[x+1+(y+1)*50], d[x+1+(y+1)*50]);
ofVertex(w[x+(y+1)*50], h[x+(y+1)*50], d[x+(y+1)*50]);

I’m trying to animate ofNoise() but curently it takes aprox. 0.5seconds to render each frame. I tried to get the same effect with ofMesh() but I didn’t know how to draw rectangles, there were gradients instead of full color and I’m not eve sure if its faster.

So, is what is the best way to aproach this problem.

Thanks in advance,

Hi, there are several way to do what you want.
BTW I cant see the linked image, you can post it directly here in the forum.

Out of all the ways you have to draw the one you are using is the slowest one, this is because each for each call of ofVertex there’s an openGL call, thus sending data to the gpu. It’s always faster to use something like an ofMesh or an ofVboMesh and then modify via openGL shader.
There’s an example that’s very much what you are trying to do in the tutorials folder in your openFrameworks install.
Take a look at it.

+1 what @roymacdonald said.

I’ve got an example of pretty much what you are trying to do here:

One simple optimisation is to keep the mesh around as a member variable and .clear() it before adding all the vertices.

Another is to only add the vertices and triangles indices once in setup() and then just move them in your update loop.

Some more noise examples here:

Hey @hahakid
those examples for the noiseworkshop are awesome!