Hi folks,
just looking for a bit of education on vertex buffers. I’m trying to draw a bunch of points via a vbo - firstly, is this fine? If yes…
I’m setting up my vbo in a custom function. The setup looks a little like this:
void My_Window::SetupBufferObject(int Size)
{
GLuint buffer = NULL;
// POSITION
glGenBuffers(1,&buffer);
PointVBO[Size][0] = buffer;
glBindBuffer(GL_ARRAY_BUFFER,buffer);
glBufferData(GL_ARRAY_BUFFER,sizeof(pointPos),pointPos,GL_DYNAMIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER,NULL,sizeof(pointPos),pointPos);
// COLOUR
glGenBuffers(1,&buffer);
PointVBO[Size][1] = buffer;
glBindBuffer(GL_ARRAY_BUFFER,buffer);
glBufferData(GL_ARRAY_BUFFER,sizeof(pointCol),pointCol,GL_DYNAMIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER,NULL,sizeof(pointCol),pointCol);
}
For the purpose of the above, PointVBO is just a vector array of int’s used for holding ids of buffers, and Size is set to 1. I’m confident the data is also good - I can draw the points manually each frame via a for loop, using pointPos and pointCol, and everything appears to be in order as far as that’s concerned. At this stage, does that look alright?
The draw calls themselves is where I don’t think I’m understanding things well. I’ve tried quite a few variations of the following, but none are getting me anywhere. I’ll post where it’s at now so you can at least see something I’ve tried with:
void My_Window::DrawGL(void)
{
... // setup/begin draw
glBindBuffer(GL_ARRAY_BUFFER,PointVBO[1][0]);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(200*100*3,GL_BYTE,3*sizeof(char),&pointPos[0]);
glBindBuffer(GL_ARRAY_BUFFER,PointVBO[1][1]);
glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(200*100*3,GL_BYTE,3*sizeof(char),0);
glDrawArrays(GL_POINTS,0,200*100);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
... // draw other/end draw
}
I’m trying to use separate buffers for the positioning and colours so that I can dig into those at some stage in the future and work on them individually. Is this where a VAO might come in handy?
What and where am I missing things here? Cheers,
WP.