当我尝试在 OpenGL 中使用 Polygon 时遇到问题。我不知道如何解释这一点,但我所有的顶点都与开始的顶点相连。当我尝试为对象着色时会出现问题。我想画一个简单的物体。
void TOP (float x1, float y1, float x2, float h,float n)
{
float r = x2-x1;
if(n==1){glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);} // FOR FILL OR NO FILL OBJECT
glBegin(GL_POLYGON);
glVertex2f(x1,y1);
glVertex2f(x2,y1);
glVertex2f(x2,y1+h/7);
y1=y1+h/7;
glVertex2f(x2-r/5,y1+h/7);
x2=x2-r/5; y1=y1+h/7;
glVertex2f(x2,y1+2*h/7);
y1=y1+2*h/7;
glVertex2f(x2+r/5,y1+h/7);
y1=y1+h/7; x2=x2+r/5;
glVertex2f(x2,y1+2*h/7);
cout<<y1<<endl;
y1=y1+2*h/7;
glVertex2f(x2-r/5,y1); x2=x2-r/5;
glVertex2f(x2,y1-h/7); y1=y1-h/7;
glVertex2f(x2-r/5,y1);x2=x2-r/5;
glVertex2f(x2,y1+h/7); y1=y1+h/7;
glVertex2f(x2-r/5,y1);x2=x2-r/5;
glVertex2f(x2,y1-h/7); y1=y1-h/7;
glVertex2f(x2-r/5,y1);x2=x2-r/5;
glVertex2f(x2,y1+h/7); y1=y1+h/7;
glVertex2f(x2-r/5,y1);x2=x2-r/5;
glVertex2f(x2,y1-2*h/7);y1=y1-2*h/7;
glVertex2f(x2+r/5,y1-h/7);y1=y1-h/7; x2=x2+r/5;
glVertex2f(x2,y1-2*h/7); y1=y1-2*h/7;
glVertex2f(x2-r/5,y1-h/7); y1=y1-h/7;x2=x2-r/5;
glVertex2f(x2,y1-h/7);
glEnd();
}
输出: