Reputation: 491
Here's a function that I wrote that draws a spiral:
void drawSpiral(GLfloat x1, GLfloat y1, GLfloat radius)
{
int lineAmount = 500;
GLfloat piMultiplier = 10.0f * 3.141592654;
glBegin(GL_LINES);
for (int i = 0; i <= lineAmount; i++)
{
GLfloat theta = i/lineAmount*piMultiplier;
GLfloat x = x1 + (radius*cos(i*piMultiplier/lineAmount));
GLfloat y = y1 + (radius*sin(i*piMultiplier/lineAmount));
glVertex2f(x, y);
radius += 1;
}
glEnd();
}
The problem is that the spiral gets drawn as dotted lines instead of one contiguous line.
I can get a continuous line using GL_LINE_LOOP instead of GL_LINES, but that (understandably) draws a line from the middle to outside of the spiral. So I know my logic is good, I'm just not sure whats the opengl way of doing this.
Upvotes: 0
Views: 962
Reputation: 2154
You can either do:
GL_LINES
with an array of vertex like: [start, end, start, end...]
. In this case, you would need a very redundant array like: [A, B, B, C, C, D]
GL_LINE_STRIP
with an array of vertices like [A, B, C, D]
GL_LINE_LOOP
will create a line between the final vertex and the first, I don't think that's what you want.
In short, use GL_LINE_STRIP
rather than GL_LINES
.
Upvotes: 4