VBO questions

Started by
13 comments, last by CyberSlag5k 19 years, 1 month ago
I still can't seem to find out what I've done wrong with the VBOs. Perhaps the silence to mean everybody concures, that I've made no mistakes and that my record of life-long infallibility continues!
Without order nothing can exist - without chaos nothing can evolve.
Advertisement
heh, i'm sorry to say you have done something wrong [wink]

You are using VBOs as a source for the data, which means you need to tell OpenGL that it needs to look in the currently bound VBO for the data, this applies as much to the index as it does to the vertex data.

So, when you us a VBO for vertex data you use;
glbindBuffer(GL_ARRAY_BUFFER_ARB, somebuffer);glVertexPointer(3, GL_FLOAT, sizeof(myStruct), BUFFER_OFFSET(0));where the offset tells it how far into the VBO to find the first peice of data.The same applies for the final drawing call, you have to tell OpenGL that you are wanting it to draw using a VBO as the source for the indices...glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, someindexbuffer);glDrawRangeElements(GL_TRIANGLES, 0, numVert-1, numIndex, GL_UNSIGNED_INT,BUFFER_OFFSET(0));

where again, the bufferoffset(0) tells OGL how far into the VBO to look for the first index.

An important point here;
Make sure you use GL_ELEMENT_ARRAY_BUFFER_ARB as the target. This is important as its a different binding point to GL_ARRAY_BUFFER_ARB. Meaning that you can do this;
glbindBuffer(GL_ARRAY_BUFFER_ARB, somebuffer);glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, someindexbuffer);glVertexPointer(3, GL_FLOAT, sizeof(myStruct), BUFFER_OFFSET(0));glDrawRangeElements(GL_TRIANGLES, 0, numVert-1, numIndex, GL_UNSIGNED_INT,BUFFER_OFFSET(0));

and the glVertexPointer() will still be using somebuffer and the glDrawRangeElements() will be using someindexbuffer.

If you dont get it from that, think of it like this;
You have two varibles, foo and bar.
Now, when you bind a buffer to the GL_ARRAY_BUFFER_ARB attachment point its number is stored in foo and any gl*Pointer() calls which happen afterwards will look in foo for the VBO to use.
When you bind a buffer to GL_ELEMENT_ARRAY_BUFFER_ARB attachment point its number is stored in bar and only drawing operations read from bar, so you can set bar when you like and it wont be changed until you try to bind something to that attachment point again and it wont be read until you issue a draw command.
Thank you for your response, _the_phantom_.

Quote:
heh, i'm sorry to say you have done something wrong


Damn! Oh well, it had to happen some day ;).

Ok, I think I'm closer. I do this to create the VBOs:

pglGenBuffersARB(2, buffList);pglBindBufferARB(GL_ARRAY_BUFFER_ARB, buffList[0]);pglBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(*vertList), vertList, GL_STATIC_DRAW);pglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, buffList[1]);pglBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(*indexList), indexList, GL_STATIC_READ);


and this to render:

pglBindBufferARB(GL_ARRAY_BUFFER_ARB, buffList[0]);glNormalPointer(GL_TRIANGLES, sizeof(struct _Vertex), BUFFER_OFFSET(0));glVertexPointer(3, GL_TRIANGLES, sizeof(struct _Vertex), BUFFER_OFFSET(12));pglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, buffList[1]);pglDrawRangeElements(GL_TRIANGLES, 0, numVerts-1, indexLength, GL_UNSIGNED_INT, BUFFER_OFFSET(0));


It looks good to me, but I must be doing something wrong as it blows up on the call to pglDrawRangeElements(). I set the index VBO as a GL_STATIC_READ because I figured it was only being used for drawing indirectly. Using GL_STATIC_DRAW didn't help, though.

Thanks in advance!

[Edited by - CyberSlag5k on March 14, 2005 10:19:16 AM]
Without order nothing can exist - without chaos nothing can evolve.
define 'blows up'?
Quote:Original post by _the_phantom_
define 'blows up'?


Program ignites in a ball of flaming code and cinder.

Or, if you'd like a more technical definition, my debugger tells me this:

Unhandled exception at 0x04e4642a in project3.exe: 0xC0000005: Access violation reading location 0x00000000.

EDIT:
Made a few changes but it's still not quite there. I now multiply the size of each piece of data by the number of elements in each array (I was before only passing the VBO the size of a single element), and I noticed that the call to pglBufferDataARB() had GL_ARRAY_BUFFER_ARB for the index VBO. I changed it to the appropriate GL_ELEMENT_ARRAY_BUFFER_ARB. It now looks like this:

pglGenBuffersARB(2, buffList);pglBindBufferARB(GL_ARRAY_BUFFER_ARB, buffList[0]);pglBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(*vertList) * numVerts, vertList, GL_STATIC_DRAW);pglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, buffList[1]);pglBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, sizeof(*indexList) * numIndex, indexList, GL_STATIC_READ);


It still crashes on the call to pglDrawRangeElements :(. Oh well, back to stare at the code for a while longer before one of you says "Silly CyberSlag, you forgot to..."

[Edited by - CyberSlag5k on March 14, 2005 4:47:26 PM]
Without order nothing can exist - without chaos nothing can evolve.

This topic is closed to new replies.

Advertisement