【发布时间】:2019-06-04 11:24:25
【问题描述】:
我最近使用 pygame 和 pyopengl 在 python 3 中构建了一个 obj 文件加载器。它工作得很好,但是当我加载一个圆形物体时,它开始运行得很慢。我想以不错的帧速率加载多个复杂对象,但这种方法不适合。你有什么建议可以更有效地编写代码,用 pygame/pyopengl 换取不同的东西,或者(如果上述方法都不起作用)也许对对象进行下采样? (重要部分代码如下)
# verticies is a list of all verticies
# surfaces holds tuples of indexes of verticies
def body():
glBegin(GL_TRIANGLES)
for surface in surfaces:
for vertex in surface:
glVertex3fv(vertices[vertex])
glEnd()
pygame.init()
size = (800,600)
pygame.display.set_mode(size, DOUBLEBUF|OPENGL)
while True:
body()
【问题讨论】:
-
由
glBegin/glEnd序列绘制,固定函数矩阵堆栈和固定函数,每个顶点光模型,几十年来已被弃用。阅读Fixed Function Pipeline 并查看Vertex Specification 和Shader,了解最先进的渲染方式。 -
非常感谢@Rabbid76,肯定会尝试一下:)
标签: python python-3.x 3d pygame pyopengl