Reputation: 16484
I am attempting to draw a hollow cylinder using OpenGL. (The body of a rocket.) I am currently using a GL_TRIANGLE_STRIP
to do this.
This is how I generate my "vertexes":
GLfloat *rocket_body_verticies = new GLfloat[3 * 20];
for(int i = 0; i < 20; ++ i)
{
const GLdouble step = 2.0 * CONST_PI / (double)(20);
rocket_body_verticies[3 * i + 0] = 0.25 * std::cos(i * step);
rocket_body_verticies[3 * i + 1] = 0.25 * std::sin((i * step + 0.5 * step));
rocket_body_verticies[3 * i + 2] = 1.0 * (i % 2 == 0 ? -0.5 : 0.5);
}
I then draw this later using: (After enabling the buffer object etc.)
glDrawArrays(GL_TRIANGLE_STRIP, 0, 20);
This produces a triangle strip, but does not join the final section of the "rocket body". There is a rectangular slice of the cylinder which is not drawn.
I could correct this by changing the "20" to a "22" in the for
loop index i
. Or I could change the step to: step = 2.0 * PI / 18.0
. Hence I would be drawing points on top of other points. This seems like it might not be the best method.
Is there a better method I can use? I am fairly sure there is no such object as a TRIANGLE_STRIP_LOOP
.
Upvotes: 1
Views: 3119
Reputation: 26539
I could correct this by changing the "20" to a "22" in the for loop index i. Or I could change the step to: step = 2.0 * PI / 18.0. Hence I would be drawing points on top of other points. This seems like it might not be the best method.
You need to repeat the two starting points of the cylinder to close it. You can do this either by repeating the vertex (pretty easy and minimal impact for a simple model like this) or using an element buffer to specify vertices more than once (better for more complex models where vertices are repeated more often, which isn't the case here).
Upvotes: 2