Hi,
I need to use VBO method in a program where I need to draw 7 joints of a robot. Those joints are, each one, an object of “Joint” class.
This class has a function to initialize the arrays:
void Joint::initArray()
{
vertexArray = new GLfloat[sizeVertex];
normalArray = new GLfloat[sizeNormal];
Vertex v;
Vertex n;
int i = 0;
int j;
for(j=0;j<vertexVector.size();j++)
{
v = vertexVector[j];
vertexArray[i] = v.x;
vertexArray[i+1] = v.y;
vertexArray[i+2] = v.z;
i+=3;
}
i = 0;
for(j=0;j<normalVector.size();j++)
{
n = normalVector[j];
normalArray[i] = n.x;
normalArray[i+1] = n.y;
normalArray[i+2] = n.z;
i+=3;
}
GLuint vertexs,normals;
glGenBuffers(1,&vertexs);
glBindBuffer(GL_ARRAY_BUFFER,vertexs);
glBufferData(GL_ARRAY_BUFFER,sizeVertex*sizeof(GLfloat),vertexArray,GL_DYNAMIC_DRAW);
glVertexPointer(3,GL_FLOAT,3*sizeof(GLfloat),0);
glGenBuffers(1,&normals);
glBindBuffer(GL_ARRAY_BUFFER,normals);
glBufferData(GL_ARRAY_BUFFER,sizeNormal*sizeof(GLfloat),normalArray,GL_DYNAMIC_DRAW);
glNormalPointer(GL_FLOAT,3*sizeof(GLfloat),0);
}
After that, I have a render function:
void Joint::render()
{
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_TRIANGLES,0,sizeVertex);
glDisableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glDrawArrays(GL_TRIANGLES,0,sizeNormal);
glDisableClientState(GL_NORMAL_ARRAY);
}
I think that everything is ok but the program just draw the first join. Do you know where’s the problem?
I thinnk it’s in the buffer’s name but in this case, I don’t know how to solve it. Can someone help me plz?
Thanks