PDA

View Full Version : Using VBO



B_old
08-04-2003, 01:12 AM
Hello.
I want to try out VBO on my GeForce 2 GTS.
I use the extgl-library to load the extension. The first strange thing is that
although extgl_ExtensionSupported("GL_ARB_vertex_buffer_object") returns true, the extension is not loaded, so I forced it to be loaded (driver: 44.03).
Still I can't get it to render correctly, which hopefully is due to my wrong usage and not the uncapable hardware.
Here's my code, please have a look:



//normal VA
glVertexPointer(3, GL_FLOAT, sizeof(cSWOVertex), &m_pVertices[0].Pos);
glEnableClientState(GL_VERTEX_ARRAY);

glClientActiveTextureARB(GL_TEXTURE0_ARB);
glTexCoordPointer(2, GL_FLOAT, sizeof(cSWOVertex), &m_pVertices[0].TexCoord);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

//for i triangles
glBindTexture(GL_TEXTURE_2D, m_pTexIDs[m_pTriangles[i].TexID]);
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, m_pTriangles[i].Indices);


//VBO
#define BUFFER_OFFSET(i) ((char *)NULL + (i))

glBindBufferARB(GL_ARRAY_BUFFER_ARB, 1); //only calling this already corrupts the drawing
glBufferDataARB(GL_ARRAY_BUFFER_ARB, m_NumVertices, m_pVertices, GL_STATIC_DRAW_ARB);

glBindBufferARB(GL_ARRAY_BUFFER_ARB, 1);

glVertexPointer(3, GL_FLOAT, sizeof(cSWOVertex), 0);
glEnableClientState(GL_VERTEX_ARRAY);

glClientActiveTextureARB(GL_TEXTURE0_ARB);
glTexCoordPointer(2, GL_FLOAT, sizeof(cSWOVertex), BUFFER_OFFSET(4*3)); //4*3 -> Pos has 3 floats
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

//for i triangles
glBindTexture(GL_TEXTURE_2D, m_pTexIDs[m_pTriangles[i].TexID]);
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, m_pTriangles[i].Indices);

Thanks a lot!

EDIT:
It works now, like this:



glBufferDataARB(GL_ARRAY_BUFFER_ARB, m_NumVertices * sizeof(cSWOVertex), (void*)m_pVertices, GL_STATIC_DRAW_ARB);

The app crashes when it is closed after running in fullscreen mode though.
What could this depend on?

It also worries me that extgl wouldn't load the extension for me although it obviously works!

[This message has been edited by B_old (edited 08-04-2003).]