VBO Woes

Started by
13 comments, last by CyberSlag5k 19 years ago
This is a continuation of my post "VBO questions". I feel it's time for a new post as the other one is days old and I'm soooo close to getting these guys working. But I'm still experiencing some troubles. Here is the VBO setup code:

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(*indices) * numInd, indices, GL_STATIC_DRAW); 


and here is the render code:

pglBindBufferARB(GL_ARRAY_BUFFER_ARB, buffList[0]);
glNormalPointer(GL_TRIANGLES, sizeof(*vertList), BUFFER_OFFSET(0));
glVertexPointer(3, GL_TRIANGLES, sizeof(*vertList), BUFFER_OFFSET(12));

pglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, buffList[1]);
pglDrawRangeElements(GL_TRIANGLES, 0, numVerts-1, numInd, GL_UNSIGNED_INT, BUFFER_OFFSET(0)); 


The program crashes with a memory access error on the call to pglDrawRangeElements and I really can't figure out why. I check to make sure that the extension is indeed supported. Can anybody see what I'm doing wrong?
Without order nothing can exist - without chaos nothing can evolve.
Advertisement
My best guess is that somewhere your calling glEnableClientState(x) and you never disable it so your code ends up trying to access, not only normals and vertices, but some other stuff, and the actuall memory you have for x, is smaller than the amount you are rendering using your vertex buffers so you overrun that array. So check for extra glEnableClientState(GL_TEXTURE_COORD_POINTER) and such lyin around

Hope that helps
-Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."
Thanks Dan. These are the only VBO/VA's I use in the program, though. The entire program centers around a single object, so I'm quite certain there are no loose client state ends. Even so, I've disabled the two I'm using after I use them.
Without order nothing can exist - without chaos nothing can evolve.
Doh! Someone on another forum just pointed out that I'm specifying a size when I'm setting my VA pointers, which I should not be doing when using VBOs. Think that's my problem? I'm going to try it out first thing tomorrow morning.

However don't take this as an excuse for you guys not to scour my code for more stupid mistakes! Afterall, what am I paying you people for?
Without order nothing can exist - without chaos nothing can evolve.
I forgot to point out on the post at CG Talk that you should specify the data type (GL_FLOAT, GL_INT...etc) in your glVertexPointer and glNormalPointer functions. GL_TRIANGLES is a primitive type and not a data type.

Wow, way to catch that, AxoDosS I cant believe i missed that :-/. Though this, i dobt believe, woudl create an access violation. Can we see your vertex setup code?
thanks
-Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."
Quote:Original post by AxoDosS
I forgot to point out on the post at CG Talk that you should specify the data type (GL_FLOAT, GL_INT...etc) in your glVertexPointer and glNormalPointer functions. GL_TRIANGLES is a primitive type and not a data type.


Wow, good call AxoDosS. That was silly of me.

Ok, so it no longer crashes but when I switch to the VBO, the whole object goes to hell. It draws somewhat like it should, only the triangles are all scrambled. In other words, it looks like it's drawing to the right vertices, just not at all in the right order. Well, I shouldn't even say it's drawing to the right vertices as there is one vertex out in the middle of no where that thousands of triangles are binding to.

The first problem, the scrambled triangles binding to appropriate, but misordered vertices, suggests there's a problem with the index list. The second, the random vertex out in the middle of no where, would suggest there's a problem with the vertex list. I've been staring at this thing for 2 hours now and I can't see what I'm doing wrong.

I've checked the index list, it matches perfectly with the one used to draw the object using a display list (which works properly). It has the same number of elements and (as near as I can tell, there are thousands) the same values. The list of vertices is the exact same as the one that the display lists draw from, so I doubt there's a problem there.

Here is what I have so far:

setup:
pglGenBuffersARB(2, buffList);	pglBindBufferARB(GL_ARRAY_BUFFER_ARB, buffList[0]);eglBufferDataARB(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(*index) * numInd, index, GL_STATIC_DRAW);


render:
pglBindBufferARB(GL_ARRAY_BUFFER_ARB, buffList[0]);glNormalPointer(GL_FLOAT, 0, BUFFER_OFFSET(0));glVertexPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(12));pglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, buffList[1]);pglDrawRangeElements(GL_TRIANGLES, 0, numVerts-1, numInd, GL_UNSIGNED_INT, BUFFER_OFFSET(0));


I'm completely clueless as to what's going wrong here. I've checked just about all of the values I'm passing to the VBO, but if there's anything I should pay special attention to, I'd be happy to double (or rather triple) check anything.

Thanks for everyone's help, thus far. This is driving me crazy.
Without order nothing can exist - without chaos nothing can evolve.
I'm slightly worried about sizeof(*index) * numInd and sizeof(*vertList) * numVerts in the code, what are the two varible being deferenced?
*indices is a pointer to a dynamic array of unsigned ints
numInd is the number of elements in that array

*vertList is a pointer to a dynamic arary of type struct _Vertex, which holds 2 Vectors (which is a class with only 3 floats)
numVerts is the number of unique vertices
Without order nothing can exist - without chaos nothing can evolve.
try switching that code to sizeof(_Vertex)*numVerts and sizeof(unsigned int)*numInd as i dont think that code is doing what you think it does..

oh, and using an unsigned short (whatever the gl type for that is, glushort i think) for indices is a much better idea, gfx cards can choke a bit on over 65K verts and you save half the space vs ints

This topic is closed to new replies.

Advertisement