Results 1 to 3 of 3

Thread: glDrawElements usage

  1. #1
    Junior Member
    Join Date
    Apr 2009
    Posts
    4

    glDrawElements usage

    Hi, all!
    I'm trying to draw a square as a pair of triangles. I'm using glDrawElements, but the program crashes!
    What did I do wrong?
    ==========================================
    GLshort vertex[] =
    {
    0,0,
    0,50,
    50,50,
    50,0
    };

    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(2, GL_SHORT, 0, vertex);

    GLubyte index[] = { 0,1,2, 0,2,3};
    glDrawElements( GL_TRIANGLE_FAN, 6, GL_UNSIGNED_BYTE, index ); // Crash, but if I write glDrawArrays it works!

    glDisableClientState(GL_VERTEX_ARRAY);
    ==========================================

    Thank you!

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

    Re: glDrawElements usage

    Are you sure all other client arrays are disabled, and that there is no buffer object bound to GL_ELEMENT_ARRAY_BUFFER?

    Also, with GL_TRIANGLE_FAN and 6 vertices, you actually get 4 triangles.
    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
    Apr 2009
    Posts
    4

    Re: glDrawElements usage

    Thank you very much,the problem has been solved out. The code is absolutely normal; the reason was an incorrect gl library build.

Similar Threads

  1. about glDrawElements
    By freesui1984 in forum OpenGL ES general technical discussions
    Replies: 3
    Last Post: 10-10-2008, 03:17 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
  •