How to set custom data to ofVbo

I want to set alpha opacity values per vertex, and have them interpolated when rendering by using ofShader. I’m using ofVboMesh and I’d like to push a VBO with the alpha values.

I guess I could use the color attribute, but it seems I’m forced to use 4 values (RGBA), and I only want to push alphas to GPU. Can I set the colorAttribute to use less than 4 values?

How should I be using the ofVbo::setAttributeBuffer function?
I’m not sure on how to get a valid location through OF API.


Making a tutorial here out of trial and error :slight_smile:

Update: I’m just using ofVbo::hasAttribute to tell if values are used, something like:

int customLocation = 5; // 

See ofShader::defaultAttributes, 0 to 4 are picked by OF’s defaults.

Someone correct me if I’m wrong… Now I’m not sure on how to upload data. I see two functions setAttributeData and setAttributeBuffer. I’m going to go with the first.

Then I can

ofVbo::setAttributeData(customLocation, &mdata[0], 1, mdata.size(), GL_STATIC_DRAW);

And in order to push to GPU:

ofVbo::updateAttributeData(customLocation, &mdata[0], mdata.size());

Then use:

ofShader::bindAttribute(customLocation, "myattribute");

And it should be accessible from your vertex shader.

Yep, OF is that self-explanatory!


yeah that’s it. setAttributeData uploads the initial data and actually allocates the buffer, if you are only uploading that data that’s it. if you need to change the data later you can use updateAttributeData