opengl正多边形

opengl正多边形,opengl,polygon,Opengl,Polygon,我有下面的代码,它什么也不画。 如果我使用glBegin(GL_点),它会画一个圆,但在多边形模式下它不会 int WXSIZE=500,WYSIZE=500; //Coordinate system float Xmin=-8, Xmax=8, Ymin=-8, Ymax=8; void setupmywindow() { glClearColor(0,0,0,0); gluOrtho2D(Xmin, Xmax, Ymin, Ymax); } void mypoly

我有下面的代码,它什么也不画。 如果我使用glBegin(GL_点),它会画一个圆,但在多边形模式下它不会

int WXSIZE=500,WYSIZE=500;

//Coordinate system
float Xmin=-8, Xmax=8, Ymin=-8, Ymax=8;

void setupmywindow()
{
    glClearColor(0,0,0,0);  
    gluOrtho2D(Xmin, Xmax, Ymin, Ymax);
}


void mypolygon(float radius) //test object
{

   glColor3f(1,0,0);
   int numPoints=20;
   float x,y;
   float centerx,centery=0;

    for (int i = 0; i < numPoints; i++)
{
    x = centerx + radius * sin(2.0*PI*i/numPoints);
    y = centery + radius * cos(2.0*PI*i/numPoints);

     glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
     glBegin(GL_POLYGON);
     glVertex2f(x, y);
     glEnd();

}

}


void myDisplay()
//single object
{
    glClear(GL_COLOR_BUFFER_BIT);
    mypolygon(2.0);
    glutSwapBuffers();
}


int main(int argc, char **argv)
{

    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
    glutInitWindowSize(WXSIZE,WYSIZE);
    glutCreateWindow("My graphic window");
    setupmywindow();
    glutDisplayFunc(myDisplay);
    glutMainLoop();
} 
int WXSIZE=500,WYSIZE=500;
//坐标系
浮点Xmin=-8,Xmax=8,Ymin=-8,Ymax=8;
void setupmywindow()
{
glClearColor(0,0,0,0);
gluOrtho2D(Xmin,Xmax,Ymin,Ymax);
}
void mypolygon(浮动半径)//测试对象
{
gl3f(1,0,0);
int numPoints=20;
浮动x,y;
浮动中心x,中心y=0;
对于(int i=0;i
有什么建议吗

编辑----------------------

glBegin(GL_POLYGON);

    for (int i = 0; i < numPoints; i++)
{
    x = centerx + radius * sin(2.0*PI*i/numPoints);
    y = centery + radius * cos(2.0*PI*i/numPoints);

    glVertex2f(x, y);

}
   glEnd();
glBegin(GL_多边形);
对于(int i=0;i

我把它弄乱了。你的多边形好像在错误的一边。默认情况下,OpenGL仅显示需要逆时针指定的正面。你可以:

  • 反转原语的顺序(
    for(int i=numPoints-1;i>=0;i--)
  • 倒置正面(
    glFrontFace(GL_-CW)
  • 禁用背面消隐(
    glDisable(GL\u消隐面)

    • 在每个循环中,您都在绘制一个多边形,该多边形由一个顶点组成,因此没有任何内容。只需将
      glBegin/glEnd
      (和
      glPolygonMode
      )放在for循环的外部,并且只在循环中绘制
      glVertex
      。当然,它适用于点,因为一个n乘以一个点等于n个点。但是由一个点组成的n个多边形与由n个点组成的一个多边形不同。

      当您调用glBegin with GL_polygon时,我相信至少需要三个顶点。标准的绘制协议是使用三角形绘制,三个顶点一组切换,因为每个三角形面需要三个顶点。你只给它一个顶点,所以你看不到任何东西。尝试将其更改为:

      glBegin(GL_TRIANGLES);
      glVertex2f(x1, y1);
      glVertex2f(x2, y2);
      glVertex2f(x3, y3);
      glEnd();
      

      那个标题,请改一下back@Christian劳:我现在看到了你的答案。上面写着7分钟前回答过,我9分钟前编辑过。那一定是我编辑的时候。至于标题,我是想编辑评论的。我会把它改回去。但是因为你的答案和我的一样,我会接受它。但我真的没有看到你的答案