Vbo.draw() seems to draw points twice

I am in the process of learning and playing around with OF, particularly compute shaders, so am quite unfamiliar and out of my depth here.

At the moment I have an ofBufferObject that stores the 2D position vector of particles and is used in a simple compute shader to compute an updated position of the particles (which is written back to the same buffer object). To draw the particles I have a vertex buffer which is initialized to the aforementioned buffer object.

The issue I am experiencing is that the vbo.draw() function draws both the updated particles as well as the the points in their initial position, but I would like to only draw the particles in their updated position.

My, tbh uneducated, guess is that I somehow store the particles twice in the vertex buffer, once in the initial position and a second time as the updated vector positions. But other than this I have no clue as to why something like this would be happening.

Here is a screenshot as example

Hey @kinneh , are you drawing to the screen, or to an ofFbo? An ofFbo will retain what has been drawn to it previously without an ofClear().

I’m not great with compute and geometry shaders, but there are some projects in the /examples/gl/ folder that use them that could be helpful, along with other examples that use ofVbo and similar classes.

Maybe the updated particles would only be drawn if the ofVbo is sent to the shader with ofVbo::bind() instead of ofVbo::draw(). Also, the textureBufferInstancedExample might be an interesting one to look at; it uses a samplerBuffer in the vertex shader, and an ofBufferObject on the oF side.

Hey @TimChi, thanks for the reply and suggestions.
I’m drawing to the screen, so unfortunately the ofClear() hint didn’t pan out.
I’ve been following Denis Perevalov’s example as well as the /examples/gl/computeShaderParticlesExample setup on github. My code directly copies their suggested setups but for some reason theirs does not exhibit this behaviour.
How would one go about using the Vbo::bind()? The documentation merely states “This is for advanced users who might want to use ways of drawing other than draw()…” which seems promising i.t.o drawing but also got me all flustered since I definitely do not fit the first required condition :stuck_out_tongue:
In the mean time I’ll dive into the textureBufferInstancedExample as suggested to see if I can get some hints there.

Hey glad to read that you found some example code and Perevalov book. Maybe try vbo.bind() if you haven’t already; I suspect that it will get the vbo data to the shader without rendering them. Other classes in oF have .draw() and .bind(), like an ofTexture for example. Calling .draw() will make the texture accessible in the shader and render it, while calling .bind() will make it accessible without drawing it.