Currently Im just loading a vector with ~6000 spherePrimitives, then drawing them in a loop, and it is very slow (12fps).
Apparently I should use instancing for this. I’ve looked at the OF example, but it’s relatively advanced considering I just want to render a bunch of static spheres. Does anyone have a simple explanation for how I’d do this?
If they are not moving then it’ll be fast if you make a mesh containing vertex data for all the spheres you want to draw.
You’d grab a unit sphere mesh, offset it’s vertices then use ofMesh.append to add it to a final starfield mesh that would end up containing the vertex data to draw all the spheres in the right position with one draw call.
It may even be faster to update the mesh each frame with moving spheres than drawing the spheres in a loop.
So, after I append the sphere vertices to the mesh, I’ve got a bunch of vertices in the mesh that draw will interpret as triangles. How do I then make the spheres look like spheres, instead of like a collection of triangles like this:
oh wow, yeah that’s almost exactly what Im doing, except I was using sphere.set before adding to the mesh. Do you know why sphere.set makes the spheres look like the image in my second post? And, how do I set the size of the shape before adding to the mesh otherwise?
Hmm, I’m not sure but it might have to do with the fact that the third argument of set is ofPrimitiveMode, and if you don’t specify it, it defaults to a triangle strip. I’m not sure why that would effect the way the mesh draws though. Try calling sphere.set with OF_PRIMITIVE_TRIANGLES as the third argument and see if that does it.
Oh good, I’m glad that works! That was a bit of a shot in the dark honestly. I’d still like to know why that even matters since you’re telling the mesh to draw using triangles anyways. I would think that would override anything the sphere’s mesh was set to. Maybe @hahakid can shed some light on this?