using VBO with OGL ?

Started by
6 comments, last by Brother Bob 17 years, 9 months ago
hi there i am experiencing with VBO with OGL, and is running into some issue with it. The geometry render correctly (shape-wise), but its texCoord seems to be messed up (they are all being tiled/repected zillion times)... below are the sample code orginal OGL and VBO-ed version. The orginal OGL version work fine (with correct UV) if anyone know as to why it doesnt work, it would be extremely helpful. thanks in advance. ===== OGL version ========== glVertexPointer( 3, GL_FLOAT, 0, nVertexArray ); glEnableClientState( GL_VERTEX_ARRAY ); glTexCoordPointer( 2, GL_FLOAT, 0, nTexCoordArrays[0] ); glEnableClientState( GL_TEXTURE_COORD_ARRAY ); float and[4] = { 0.5f, 0.5f, 0.5f, 0.0f }; glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, and ); glDrawElements( nPrim, nIndexCount, GL_UNSIGNED_INT, nIndexArray ); ===== VBO version ========== // generate mutliple VBO for each vertex stream // glGenBuffersARB( CLightmapData::cVBOlast, data->mVBOnames ); glBindBufferARB( GL_ARRAY_BUFFER_ARB, data->mVBOnames[CLightmapData::cVBOpos] ); glBufferDataARB( GL_ARRAY_BUFFER_ARB, nVertexCount * 3 * sizeof(GLfloat), nVertexArray, GL_STATIC_DRAW_ARB ); glBindBufferARB( GL_ARRAY_BUFFER_ARB, data->mVBOnames[CLightmapData::cVBOuv0] ); glBufferDataARB( GL_ARRAY_BUFFER_ARB, nVertexCount * 2 * sizeof(GLfloat), nTexCoordArrays[0], GL_STATIC_DRAW_ARB ); glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, data->mVBOnames[CLightmapData::cVBOidx] ); glBufferDataARB( GL_ELEMENT_ARRAY_BUFFER_ARB, nIndexCount * sizeof(GLuint), nIndexArray, GL_STATIC_DRAW_ARB ); // Now draw it // glBindBufferARB( GL_ARRAY_BUFFER_ARB, data->mVBOnames[CLightmapData::cVBOpos] ); glVertexPointer( 3, GL_FLOAT, 0, NULL ); glEnableClientState( GL_VERTEX_ARRAY ); glBindBufferARB( GL_ARRAY_BUFFER_ARB, data->mVBOnames[CLightmapData::cVBOuv0] ); glTexCoordPointer( 2, GL_FLOAT, 0, NULL ); glEnableClientState( GL_TEXTURE_COORD_ARRAY ); float and[4] = { 0.5f, 0.5f, 0.5f, 0.0f }; glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, and ); glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, data->mVBOnames[CLightmapData::cVBOidx] ); glDrawElements( nPrim, nIndexCount, GL_UNSIGNED_INT, NULL ); [Edited by - nothappy0 on July 6, 2006 3:00:30 AM]
Advertisement
Can i see your data classes/initializations i dont understand why nTexCoordArrays[0] has the array while the rest are just pointers...
----------------------------

http://djoubert.co.uk
Code looks correct. You might want to check that the texture matrix is set properly in both cases. Also, you should be interleaving the data inside a single VBO rather than use a collection of VBOs, as you are using a STATIC buffer (the model doesn't change between frames).
try to enable the client state _before_ binding the data!

Cirdan
From what I can tell, you're using a separate VBO for vertex coordinates and texture coordinates. This is not correct. You need to put the entire data into different parts of the VBO, so you need to do something along the lines of:

/* Create only one VBO */GLuint vbo;glGenBuffersARB(1, &vbo);/* Allocate an array big enough to hold the whole data */size_t vertex_array_size = nVertexCount * 3 * sizeof(GLfloat);size_t texcoord_array_size = nVertexCount * 2 * sizeof(GLfloat);char* temp = malloc(vertex_array_size + texcoord_array_size);/* Fill the array with the vertex data */memcpy(temp, nVertexArray, vertex_array_size);/* Fill the rest of the array with texture coordinate data */memcpy(temp + vertex_array_size, nTexCoordArrays[0], texcoord_array_size);/* Copy the whole thing into the VBO */glBufferDataARB( GL_ARRAY_BUFFER_ARB, vertex_array_size + texcoord_array_size, temp, GL_STATIC_DRAW_ARB );free(temp);


That should hopefully do the trick.

EDIT: Note that the glTexCoordPointer() call must be changed to this:
glTexCoordPointer( 2, GL_FLOAT, 0, (char*)NULL + vertex_array_size);

To correctly take into account the position of the texture coordinate data within the VBO.

~phil
~phil
Quote:Original post by JonnyQuest
From what I can tell, you're using a separate VBO for vertex coordinates and texture coordinates. This is not correct. You need to put the entire data into different parts of the VBO, so you need to do something along the lines of:


Bzzzt! wrong.
It is perfectly legal to place different data into different VBOs, it might not be optimial from a data fetching point of view but it IS perfectly legal to do so.

Quote:Original post by phantom
Bzzzt! wrong.
It is perfectly legal to place different data into different VBOs, it might not be optimial from a data fetching point of view but it IS perfectly legal to do so.

Oops, sorry about that, I must have seriously misread the VBO spec then. Interesting. How exactly do you use them, bind the VBO, set the array data, bind another VBO, then set the rest of the array data?

~phil
~phil
Quote:Original post by JonnyQuest
How exactly do you use them, bind the VBO, set the array data, bind another VBO, then set the rest of the array data?
~phil

Yes.

This topic is closed to new replies.

Advertisement