I am use vertex buffers (in a fixed function pipeline) to batch triangle strips by repeating first/last vertices. The rendering code is as follows:
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer); // enable vertex array glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, 3*sizeof(GLfloat), 0); // prepare color VBO glBindBuffer(GL_ARRAY_BUFFER, _colorBuffer); // enable color array glEnableClientState(GL_COLOR_ARRAY); glColorPointer(3, GL_FLOAT, 3*sizeof(GLfloat), 0); // prepare normals VBO glBindBuffer(GL_ARRAY_BUFFER, _normalBuffer); // enable normal array glEnableClientState(GL_NORMAL_ARRAY); glNormalPointer(GL_FLOAT, 0, 0); glDrawArrays(mode, 0, _nVertices); // disable/unbind glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, 0);
But, although the triangle strips are separated correctly, the lighting is correct only for the first triangle strip.
In the example below, I am rendering a pentagon and a square, and you can see that the lighting is correct only for the pentagon.
This is the data in the 3 (vertex, normal, color) vertex buffers. You can see that the last vertex of the pentagon and the first vertex of the square is repeated, and that the normals are consistent.
vertices: -2.000000 1.000000 0.000000 -1.000000 0.000000 0.000000 -1.000000 2.000000 0.000000 0.000000 0.000000 0.000000 0.000000 2.000000 0.000000 0.000000 2.000000 0.000000 1.000000 -1.000000 0.000000 1.000000 -1.000000 0.000000 1.000000 -2.000000 0.000000 2.000000 -1.000000 0.000000 2.000000 -2.000000 0.000000 normals: -0.000000 0.000000 1.000000 -0.000000 0.000000 1.000000 -0.000000 0.000000 1.000000 -0.000000 -0.000000 1.000000 -0.000000 0.000000 1.000000 -0.000000 0.000000 1.000000 -0.000000 0.000000 1.000000 -0.000000 0.000000 1.000000 -0.000000 0.000000 1.000000 -0.000000 0.000000 1.000000 -0.000000 -0.000000 1.000000 colors: 0.317647 0.011765 0.458824 0.317647 0.011765 0.458824 0.317647 0.011765 0.458824 0.317647 0.011765 0.458824 0.317647 0.011765 0.458824 0.317647 0.011765 0.458824 0.678431 0.003922 0.003922 0.678431 0.003922 0.003922 0.678431 0.003922 0.003922 0.678431 0.003922 0.003922 0.678431 0.003922 0.003922
Why is the lighting wrong for the square?
glEnable (GL_NORMALIZE);
. – Yno