Karish Karish
Karish Karish

Reputation: 269

opengl multiple pentagons

i am trying to generate multiple pentagons but for some reason the pentagons are connected to each other. any suggestions?

GLfloat arr[] = {100,200,340,230,130,190,200,190,260,120,200};

glColor3f(1.0, 1.0, 1.0);
GLfloat angle2, r2, r_big_circle2, r_small_circle2, step2 = 3.14 / 5.0;
r_big_circle2 = 25;
r_small_circle2 = 20;

glPushMatrix();

glBegin(GL_LINE_LOOP);
for (int n = 0; n < 5; n++){
    for (int i = 0; i < 10; i++)
    {
        r2 = (i % 2 == 0 ? r_small_circle2 : r_big_circle2);
        angle2 = step2 * i;
        glVertex3f(r2 * cos(angle2)-arr[n], r2 * sin(angle2)-arr[n], -500);
    }

}
glEnd();
glPopMatrix();

Upvotes: 3

Views: 151

Answers (1)

Jacob Parker
Jacob Parker

Reputation: 2556

Move glBegin and glEnd inside the first for loop. Also a GL_LINE_LOOP for an 5 sided polygon should have only 5 points specified with glVertex3f - you are drawing each pentagon twice, once on top of itself. Try:

for (int n = 0; n < 5; n++) {
    glBegin(GL_LINE_LOOP);
    for (int i = 0; i < 5; i++) {
        r2 = (i % 2 == 0 ? r_small_circle2 : r_big_circle2);
        angle2 = step2 * i;
        glVertex3f(r2 * cos(angle2)-arr[n], r2 * sin(angle2)-arr[n], -500);
    }
    glEnd();
}

Upvotes: 5

Related Questions