How to use vbo.setAttributeBuffer

I want to use custom type in VBO through using setArrtibuteBuffer. I have found a topic about this, but I still can’t work it out, I can’t find where is the problem. So I decide to post my code and looking for help.

Best!

In the head File

ofBufferObject particleBuffer;
ofVbo vbo;
ofShader updateVel;
vector<myParticle> testParticles;

In the setup function

void ofApp::setup(){
	updateVel.load("/updateVel.vert", "/updateVel.frag");

	ofViewport(500, 500);
	testParticles.resize(numPar);
	int sz = 5;
	for (auto &p : testParticles) {
		p.pos = ofVec4f(ofRandom(ofGetWidth() - sz * 2), ofRandom(ofGetHeight() - sz * 2), 0, 1.0f);
		p.pos += ofVec4f(sz, sz, 0, 0);
		p.vel.set(0,0,0,0);
	}

	updateVel.begin();
	particleBuffer.allocate(testParticles, GL_DYNAMIC_DRAW);
	vbo.setAttributeBuffer(0, particleBuffer, 4, sizeof(myParticle), offsetof(myParticle, pos));
	vbo.setAttributeBuffer(1, particleBuffer, 4, sizeof(myParticle), offsetof(myParticle, vel));
	updateVel.end();
	
}

In the update function

void ofApp::update(){
	particleBuffer.updateData(testParticles);
}

In the draw function

void ofApp::draw(){
	ofSetColor(125);
    updateVel.begin();
	glPointSize(5);
	vbo.draw(GL_POINT, 0, testParticles.size());
	updateVel.end();
}

In vertex shader

#version 330

layout(location = 0) in vec4 position;
layout(location = 1) in vec4 velosity;

void main() {
	gl_Position = position;
}

In fragment shader

#version 330

out vec4 color;

void main() {
	color = vec4(0.2, 0.3, 0.4, 1.0);
}

Hi! @Hanxin_Jia
I am not familiar with VAO and VBO’s behavior… Here is my minimal examples for study. Transform Feedback, and simple triangle
It may be useful for you.


cheers!!