View Full Version : Probem with glDrawElement with my Vertex Buffer Object

06-02-2007, 07:26 AM
I try to apply the same code like in this tutorial http://www.g-truc.net/article/vbo-fr.pdf , by using a vertex buffer and an index buffer but my program does a crash. It just works ten seconds when i use the function glDrawElement whereas when i use glDrawArrays everything is ok. It's a problem with memory but normaly it should work. I really want to use an index buffer to improve my program, can you help me please???

I use the PowerVR Insider OpenglEs 1.1 library because the functions like glBindBuffer, glGen .... don't exist in the 1.0 version.
If you have a sample code which works, i want it.

Thanks for your help

06-04-2007, 03:19 AM

do you have a minimal code that shows this behaviour? Which version of the PowerVR SDK are you using?

06-04-2007, 05:31 AM
Of course:

static const GLushort vertexArray[] = {-25,-25,0, 25,-25,0, 0,25,0 };
static const GLushort IndexData[] =
0, 1, 2
glGenBuffers(1, &VertexBuffer);
glGenBuffers(1, &indexBuffer);

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, 3*sizeof(GLushort), IndexData, GL_STATIC_DRAW);

glBufferData(GL_ARRAY_BUFFER, 3*3*sizeof(GLushort), vertexArray, GL_STATIC_DRAW);

glVertexPointer(3, GL_SHORT, 0, NULL);

//glDrawArrays(GL_TRIANGLES, 0, 3);
glDrawElements(GL_TRIANGLES,3*sizeof(GLushort),GL_ UNSIGNED_SHORT, 0);

glBindBuffer(GL_ARRAY_BUFFER, 0);

This code works some seconds and then i have this kind of exception:
Unhandled exception at 0x0180feff in OGLESInitialization.exe: 0xC0000005: Access violation reading location 0x0196064a.

06-05-2007, 03:49 AM
glDrawElements(GL_TRIANGLES,3*sizeof(GLushort),GL_ UNSIGNED_SHORT, 0);
It should work if you remove the bold part. This parameter is the number of vertices, not the size of the associated indices.