python - GL_QUAD 绘制三角形

标签 python opengl pyopengl opengl-compat

我正在尝试用 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:

最佳答案

这个顶点的顺序

[[   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()

或者您必须更改顶点的顺序,使其符合 GL_QUAD 的要求:

enter image description here

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

进一步查看 Primitive

关于python - GL_QUAD 绘制三角形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47965081/

相关文章:

python - 为 Python 3.6 安装 GDAL 时出现 ImportError

java - OpenGL 中透明对象中的三角形/线条

c - OpenGL-GLSL 绘制 3D GL_LINES 顶点着色器与顶点

c++ - OpenGL c++ 纹理有错误的颜色和位置

python - 在Python中使用OpenGL渲染纹理不是

python - 将数组中的重复分组?

python - 如何在Python中使用递归打印字符串的排序排列

python - 使用 Python lxml 解析 XML

python - 旋转后的 OpenGL python 和 pygame 翻译不适用于鼠标外观和移动

python - 使用 EBO 时 OpenGL 崩溃