# VBO Woes

This topic is 4897 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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?

##### Share on other sites
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

##### Share on other sites
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.

##### Share on other sites
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?

##### Share on other sites
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.

##### Share on other sites
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

##### Share on other sites
Quote:
 Original post by AxoDosSI 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.

##### Share on other sites
I'm slightly worried about sizeof(*index) * numInd and sizeof(*vertList) * numVerts in the code, what are the two varible being deferenced?

##### Share on other sites
*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

##### Share on other sites
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

1. 1
2. 2
3. 3
4. 4
frob
14
5. 5

• 16
• 13
• 20
• 12
• 19
• ### Forum Statistics

• Total Topics
632168
• Total Posts
3004543

×