GL_QUAD绘制三角形

问题描述 投票:1回答:2

我试图用GL_LINES填充由4行生成的四边形。但是,当我尝试填充四边形时,它只填充三角形。这是绘制线条的代码:

def SurfaceContour(self, vertices, edges):
     glBegin(GL_LINES)
     for edge in edges:
         for vertex in edge:
             glColor3fv((1.0, 0.0, 0.0))
             glVertex3fv(vertices[vertex])
     glEnd()

这是绘制填充四边形的代码:

def Surfaces(self,  vertices):
     glBegin(GL_QUADS)
     for i in range(4):
        glColor4f(1, 1, 1, 0.3)
        glVertex3fv(vertices[i ,:])
     glEnd()

这是我传入的顶点矩阵:

[[   0.    -20.23    7.  ]
 [   0.    -20.23   -7.  ]
 [ 100.    -10.      5.  ]
 [ 100.    -10.     -5.  ]]

This is the result that i get:

python opengl pyopengl opengl-compat
2个回答
5
投票

这个顶点的顺序

[[   0.    -20.23    7.  ]
 [   0.    -20.23   -7.  ]
 [ 100.    -10.      5.  ]
 [ 100.    -10.     -5.  ]]

是这样的:

enter image description here

如果你想绘制由4个顶点定义的四边形,那么你要么绘制一个GL_TRIANGLE_STRIP

enter image description here

def Surfaces(self,  vertices):
    glBegin(GL_TRIANGLE_STRIP)
    for i in range(4):
    glColor4f(1, 1, 1, 0.3)
    glVertex3fv(vertices[i ,:])
    glEnd()

或者你必须改变顶点的顺序,它符合qazxsw poi的要求:

GL_QUAD

enter image description here

另见[[ 0. -20.23 7. ] [ 0. -20.23 -7. ] [ 100. -10. -5. ] [ 100. -10. 5. ]]


0
投票

首先,您使用的是旧的弃用的api,glBegin / glEnd和GL_QUAD都不应该在现代应用程序中使用。

其次,glVertex3fv接收数组到一个元素,在你的代码中传递Primitive切片的原始数组,实际上只使用第一个元素,所以它等于glVertex3fv(vertices[i ,:])。这导致GL_QUAD的不正确的顶点顺序。您必须更改基元类型或元素顺序。

© www.soinside.com 2019 - 2024. All rights reserved.