2013-03-19 79 views
3

我想生成多個五邊形,但由於某種原因五邊形彼此連接。有什麼建議麼?opengl多個五邊形

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(); 

回答

5

移動glBeginglEnd第一for循環內。另外一個用於5邊多邊形的GL_LINE_LOOP應該只有glVertex3f指定的5個點 - 你正在繪製每個五角形兩次,一次在其頂部。試試:

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(); 
} 
+1

謝謝你的工作很棒 – 2013-03-19 01:42:54