Results 1 to 4 of 4

Thread: Probem with glDrawElement with my Vertex Buffer Object

  1. #1
    Junior Member
    Join Date
    May 2007
    Posts
    2

    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

  2. #2
    Senior Member
    Join Date
    May 2006
    Posts
    353
    Hi,

    do you have a minimal code that shows this behaviour? Which version of the PowerVR SDK are you using?
    Georg Kolling, Imagination Technologies
    Please ask questions specific to PowerVR hardware or SDKs on the PowerVR Insider Forum
    DevTech@imgtec.com | http://www.powervrinsider.com

  3. #3
    Junior Member
    Join Date
    May 2007
    Posts
    2
    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, 3*3*sizeof(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.

  4. #4
    Senior Member
    Join Date
    May 2006
    Posts
    353
    Quote Originally Posted by Ro3034
    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.

    Regards
    Georg Kolling, Imagination Technologies
    Please ask questions specific to PowerVR hardware or SDKs on the PowerVR Insider Forum
    DevTech@imgtec.com | http://www.powervrinsider.com

Similar Threads

  1. How does a color buffer and a vertex buffer fit together?
    By xkrja in forum Developers Coding:Beginner
    Replies: 1
    Last Post: 02-25-2011, 06:11 PM
  2. mapping of Vertex Buffer Objects
    By Lichtens in forum OpenGL ES 1.X - fixed function hardware
    Replies: 1
    Last Post: 01-19-2009, 05:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •