glDrawElements triangle being rendered using vertices from start & end of vertex array (using GL_TRIANGLE_STRIP)

StackOverflow https://stackoverflow.com/questions/14839065

Question

I'm trying to render a set of lines using a single call to glDrawElements(). Each line is a single quad, and I'm using degenerate triangles in between to separate them.

When rendered, an additional triangle is being drawn using the vertices at indices 0, n-1 and n-2, which I don't believe is normal behaviour for GL_TRIANGLE_STRIPS.

For example, with 12 vertices comprising 3 quads my index array looks like this:

(0, 1, 2, 3, 3, 4, 4, 5, 6, 7, 7, 8, 8, 9, 10, 11)

And the result is this:

Triangle rendered between first and last vertices

It doesn't matter how many vertices I'm trying to render, or how many indices I put in the index list, it still joins up the start & end with a triangle. I'm drawing using a VBO and IBO, wrapped up in a VAO. So to draw I simply call:

glBindVertexArrayOES(vao);
glDrawElements(GL_TRIANGLE_STRIP, indexCount * sizeof(GLushort), GL_UNSIGNED_SHORT, 0);
glBindVertexArrayOES(0);

VAO setup:

// Bind VAO.
glBindVertexArrayOES(vao);

// Bind and set VBO data.
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, vertexCount * sizeof(VertexStructure), vertices, GL_STATIC_DRAW);

// Enable attribute pointers.
glVertexAttribPointer(position, 2, GL_FLOAT, GL_FALSE, sizeof(VertexStructure), (void*)offsetof(VertexStructure, vertex));
glEnableVertexAttribArray(position);
glVertexAttribPointer(color, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(VertexStructure), (void*)offsetof(VertexStructure, color));
glEnableVertexAttribArray(color);

// Bind and set IBO data.
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexCount * sizeof(GLushort), indices, GL_STATIC_DRAW);

// Unbind VBO & VAO.
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArrayOES(0);

// Disable attribute pointers.                                                       
glDisableVertexAttribArray(position);
glDisableVertexAttribArray(color);


What silly thing could I possibly be doing to cause this behaviour?

Était-ce utile?

La solution

count Specifies the number of elements to be rendered.

glDrawElements(GL_TRIANGLE_STRIP, indexCount, GL_UNSIGNED_SHORT, 0);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top