Hi all
I’m trying to update a vbo from a texture using ofVBO.
I’ve done it via pure OpenGL but I want to do it the the openframeworks way
Here’s the OpenGL code, this one works (opengl 2.x)
Init VBO
const int size = texture_size_x*texture_size_y*4*sizeof(float);
/// vertex
glGenBuffers(1, &vboID);
glBindBuffer(GL_ARRAY_BUFFER, vboID);
glBufferData(GL_ARRAY_BUFFER, size, 0, GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
render:
//read back the results into the VBO
glReadBuffer(GL_COLOR_ATTACHMENT0);
glBindBuffer(GL_PIXEL_PACK_BUFFER, vboID);
glReadPixels(0, 0, texture_size_x, texture_size_y, GL_RGBA, GL_FLOAT, 0);
glEnableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, vboID);
glVertexPointer(4, GL_FLOAT, 0,0);
//draw plygons
glDrawElements(GL_TRIANGLES, (GLsizei)indices.size(), GL_UNSIGNED_SHORT, &(indices[0]));
Here is the code I’ve written using ofVBO :
declaration:
ofVbo vbo;
init:
vbo.setVertexData(0, 3, indices.size(), GL_DYNAMIC_DRAW, 4*sizeof(float));
render:
glReadBuffer(GL_COLOR_ATTACHMENT0);
glBindBuffer(GL_PIXEL_PACK_BUFFER, vbo.getVertId());
glReadPixels(0, 0, texture_size_x, texture_size_y, GL_RGBA, GL_FLOAT, 0);
vbo.bind();
vbo.drawElements(GL_TRIANGLES, indices.size());
I’m not sure of the values (I’m pretty sure they are bad) since that leads to this warning:
[warning] ofVbo: bad vertex data!
Question 1 : is setvertexdata the right call ?
Question 2 : if setvertexdata is ok, which are the good parameters ?
Question 3 : is bind the right way to call my VBO before drawing it ?
Thanks a lot for your help