Search code examples
openglparametersopengl-es-2.0vrml

glDrawElements() parameters


I want to render a 3D box by reading its geometry from a VRML file. The indices in the VRML file is given as :

coordIndex
    [
        0, 1, 2, -1,
        2, 3, 0, -1,
        3, 2, 4, -1,
        4, 5, 3, -1,
        5, 4, 7, -1,
        7, 6, 5, -1,
        6, 7, 1, -1,
        1, 0, 6, -1,
        6, 0, 3, -1,
        3, 5, 6, -1,
        1, 7, 2, -1,
        7, 4, 2, -1,
    ]

I want to call glDrawElements function to render the box but I am not sure about the "count" and "indices" parameter. Should count be 12 indicating the number of faces or 36 denoting the total indices of vertices ? Also, please tell me about the indices array. Should it be like this :

GLint indices[] = {0,1,2,2,3,0,3,2,4,.....,7,4,2};
                        OR
GLint indices[] = {0,1,2,-1,2,3,0,-1,....,7,4,2};

Solution

  • According to the man page of DrawElements

    When glDrawElements is called, it uses count sequential elements from an enabled array

    So it would be 36 for the total indices in your indexbuffer.

    For the indices array you would have to choose the first version. The indices have to be >= 0 and for 3 consecutive indices a triangle will be drawn.