Probem with glDrawElement with my Vertex Buffer Object

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
:smiley:

Hi,

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

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);

glBindBuffer(GL_ARRAY_BUFFER,VertexBuffer);
glBufferData(GL_ARRAY_BUFFER, 33sizeof(GLushort), vertexArray, GL_STATIC_DRAW);

glVertexPointer(3, GL_SHORT, 0, NULL);

glEnableClientState(GL_VERTEX_ARRAY);
//glDrawArrays(GL_TRIANGLES, 0, 3);
glDrawElements(GL_TRIANGLES,3*sizeof(GLushort),GL_UNSIGNED_SHORT, 0);

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glDisableClientState(GL_VERTEX_ARRAY);

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.

It should work if you remove the bold part. This parameter is the number of vertices, not the size of the associated indices.

Regards

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.