gpt4 book ai didi

c++ - OpenGL GL_POLYGON 凹多边形不着色

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:11:21 25 4
gpt4 key购买 nike

当我尝试在 OpenGL 中使用多边形时遇到问题。我不知道如何解释这一点,但我所有的顶点都与开始的顶点相连。当我尝试为对象着色时会出现问题。我想画一个简单的物体。

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

输出:

http://i.stack.imgur.com/BLMSJ.png

最佳答案

GL_POLYGON仅适用于 convex polygons :

GL_POLYGON: Draws a single, convex polygon. Vertices 1 through N define this polygon.

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

  1. Triangulate the polygon并使用 GL_TRIANGLES

  2. Use the stencil buffer trick .

关于c++ - OpenGL GL_POLYGON 凹多边形不着色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15556929/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com