Drawing points..

How to draw points as particles instead ofRect ?
I try ofRect & ofCircle but run very slow as i want to draw and animate around 100.000 particles.
Here is the draw code:

for ( int i = 0 ; i < particles.size() ; i++ ){  
ofSetColor( particles[i].color ,  200 ) ;  
ofRect( particles[i].pos.x , particles[i].pos.y , 1,1); // draw around 4-5 fps :-(  

This code is for iOS app,so I have no chance to use


Is there any way to draw many points faster ?

yes, in this case ofRect isn’t the best solution you can look at different approach:
and with vbo and shader glPointSprites
and this

i think you can take a look at these examples and to adapt to your idea. I think you can find other examples in the forum but at the moment i don’t remember where…

p.s. i saw now that you want to develop for ios…consider that in this case probably you will change some part of the code for GLES

1 Like

@jvcleave made this to works for GLES2 https://github.com/jvcleave/billboardExampleGLES2/blob/master/src/testApp.cpp
i tested on my PandaboardES so quite sure that should work also for IOS.

1 Like

If I remember correctly you can also use ofMesh for drawing because it uses vertex array objects, which is what GLES expects all points to be passed with. Create the points of each rectangle (or whatever shape) and add them to the ofMesh. You might also experiment with using the ofVboMesh to see if that gives better performance.

Thanks guys for driving me on right direction.

I use ofVbo & ofMesh and for the ofMesh drawing code the result is :
MacBook: 45000 particles run at ~60 fps
iPad 2: 45000 particles run at ~30 fps
iPhone 4: 45000 particles run at ~14 fps
ps: all the above results is for build in release mode, in debug mode has ~10 fps down.
Both vbo & mesh I don’t see any difference, has the same result but much better than ofrec&ofcircle.
here is the code i use for ofMesh drawing:


for ( int i = 0 ; i < particles.size() ; i++ ){  
 mesh.addVertex(ofVec2f(particles[i].pos.x, particles[i].pos.y));  

Why this code run slow on iPhone 4 than iPad 2 ?

It could just be the difference in GPU between the iPhone4 and the iPad2. I’m not sure if there’s much to change in ofVboMesh that wouldn’t be very complex and probably a small performance gain.

1 Like

If you always have the same amount of particles, you can add the vertices once in setup() and then set their positions in the update() function. mesh.setVertex(i, particles[i].pos);