hi.
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
glBegin(GL_POINTS)
Is there any way to draw many points faster ?
thanks.
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
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.
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:
//testApp::draw()
for ( int i = 0 ; i < particles.size() ; i++ ){
mesh.addVertex(ofVec2f(particles[i].pos.x, particles[i].pos.y));
}
mesh.drawVertices();
mesh.clearVertices();
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.
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);