c – OpenGL GL_POLYGON凹面多边形没有着色

前端之家收集整理的这篇文章主要介绍了c – OpenGL GL_POLYGON凹面多边形没有着色前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当我尝试在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+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();
}

输出

解决方法

GL_POLYGON仅适用于 convex polygons.

对于concave polygons,您至少有两个选择:

> Triangulate the polygon并使用GL_TRIANGLES.
> Use the stencil buffer trick.

原文链接:https://www.f2er.com/c/116480.html

猜你在找的C&C++相关文章