使用Python在OpenGL中显示列表的效率?
我一直在使用 Python 包装器 PyOpenGL 自学 OpenGL 编程,现在正在使用它开发我的第一个项目。这个项目是一个音乐可视化工具(与whitecap没有什么不同),使用许多独立移动和独立着色的立方体。
我当前的方法是为一个立方体创建一个显示列表,并使用 glColor 和 glTranslatef 反复调用它来更改颜色和位置(伪代码):
glPushMatrix()
glPushMatrix() #Why do I need to call this twice?
for x in xrange(...):
for z in xrange(...):
y = height[x,z] #numpy array
glTranslatef(x,y,z)
glColor((r,g,b))
glCallList(cube)
glTranslatef(-x,-y,-z)
glPopMatrix()
glPopMatrix()
以这种方式,在我开始注意到帧速率之前,我可以渲染大约 10,000 个立方体,这是可以的但我希望它更快,这样我的程序就可以移植到能力较差的计算机上,所以我的问题是:
渲染许多相同但不同的内容的最有效方法是什么? 独立的对象,我会得到比现在更好的性能吗 现在使用显示列表? 我应该使用 C 还是学习 vertex 缓冲?
注意:我发现禁用错误检查可以显着提高性能。
I have been teaching myself OpenGL programming using the Python wrapper PyOpenGL, and am now working on my first project with it. This project is a music visualizer (not dissimilar to whitecap) using many independently moving and independently colored cubes.
My current method is to have a display list for one cube and call it repeatedly changing color and location with glColor and glTranslatef like so (pseudocode):
glPushMatrix()
glPushMatrix() #Why do I need to call this twice?
for x in xrange(...):
for z in xrange(...):
y = height[x,z] #numpy array
glTranslatef(x,y,z)
glColor((r,g,b))
glCallList(cube)
glTranslatef(-x,-y,-z)
glPopMatrix()
glPopMatrix()
In this manner I can render about 10,000 cubes before I start to notice the framerate, this is OK but I would like it to be faster so my program is portable to less able computers, so my question is:
What would be the most efficient way to render many identical but
independent objects, and will I get much better performance than I am
now using display lists?
Should I be using C or learning vertex
buffering?
Note: I found disabling the error checking gave a sizable performance boost.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就像常识是错误的。您在绘制
立方体
后手动恢复变换(glTranslatef(-x,-y,-z)
),这样glPopMatrix
不仅无缘无故地打了两次电话,但也没什么用,因为你已经为它做了所有的工作。正确的代码会像这样:
It is like the common sense was wrong. You manually restore the transformation (
glTranslatef(-x,-y,-z)
) after drawing thecube
, this wayglPopMatrix
is not only called twice for no reason, but it is also useless because you did all the work for it.Correct code would like like so: