PDA

View Full Version : VBO krasch



Ninja
03-30-2004, 11:46 AM
Hi,

Im new at VBO and I have some problem with my program. I want to use the VBO extension and it works great for just vertices and texcoords.

But when I try to add the normals and tangents the program just krasch. Here is my code:

//Init function
void BuildVBOs(struct TDS_Mesh_t & mesh)
{

glGenBuffersARB(1, &(mesh.m_nVBOVertices));
glBindBufferARB(GL_ARRAY_BUFFER_ARB, mesh.m_nVBOVertices); // Bind The Buffer
glBufferDataARB(GL_ARRAY_BUFFER_ARB, mesh.NumVertex*3*sizeof(float), mesh.Vertex, GL_STATIC_DRAW_ARB );

glGenBuffersARB( 1, &mesh.m_nVBOTexCoords );
glBindBufferARB( GL_ARRAY_BUFFER_ARB, mesh.m_nVBOTexCoords ); // Bind The Buffer
glBufferDataARB( GL_ARRAY_BUFFER_ARB, mesh.NumVertex*2*sizeof(float), mesh.UV, GL_STATIC_DRAW_ARB );

glGenBuffersARB(1, &(mesh.m_nVBONormals));
glBindBufferARB(GL_ARRAY_BUFFER_ARB, mesh.m_nVBONormals); // Bind The Buffer
glBufferDataARB(GL_ARRAY_BUFFER_ARB, mesh.NumVertex*3*sizeof(float), mesh.Normal, GL_STATIC_DRAW_ARB );

glGenBuffersARB(1, &(mesh.m_nVBOTangents));
glBindBufferARB(GL_ARRAY_BUFFER_ARB, mesh.m_nVBOTangents);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, mesh.NumVertex*3*sizeof(float), mesh.Tangent, GL_STATIC_DRAW_ARB );
}

//Draw function
void Draw(struct TDS_Mesh_t & mesh)
{

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);

glBindBufferARB( GL_ARRAY_BUFFER_ARB, mesh.m_nVBOVertices );
glVertexPointer( 3, GL_FLOAT, 0, (char *) NULL );

glBindBufferARB( GL_ARRAY_BUFFER_ARB, mesh.m_nVBOTexCoords );
glTexCoordPointer( 2, GL_FLOAT, 0, (char *) NULL );

glBindBufferARB( GL_ARRAY_BUFFER_ARB, mesh.m_nVBONormals );
glVertexPointer( 3, GL_FLOAT, 0, (char *) NULL );

glBindBufferARB( GL_ARRAY_BUFFER_ARB, mesh.m_nVBOTangents );
glVertexPointer( 3, GL_FLOAT, 0, (char *) NULL );

glDrawElements(GL_TRIANGLES, mesh.NumFace*3, GL_UNSIGNED_SHORT, mesh.Face);

glDisableClientState( GL_VERTEX_ARRAY );
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
glDisableClientState( GL_NORMAL_ARRAY );
glDisableClientState( GL_COLOR_ARRAY );

}

I have my tangents sent through the color channel and it works nice without VBO, so thats not the problem right? Anyone see whats wrong?

//Regards, Ninja

yooyo
03-30-2004, 12:54 PM
You have call 3 times glVertexPointer in Draw().
It look like copy/paste coding...

yooyo

Ninja
03-30-2004, 01:36 PM
Ok, thanks!

//Ninja