Domanda

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};
È stato utile?

Soluzione

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.

Altri suggerimenti

Indices array should be your first example (always positive numbers, referencing vertex index).

Draw elements count should be the length of your index array. This is usually something like indices.length.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top