使用Python在OpenGL中显示列表的效率? [英] Efficiency of display lists in OpenGL with Python?

查看:130
本文介绍了使用Python在OpenGL中显示列表的效率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用Python包装器PyOpenGL自学OpenGL编程,现在正在使用它进行我的第一个项目.该项目是一个音乐可视化程序(与whitecap相同),它使用了许多独立移动和独立着色的多维数据集.

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.

我当前的方法是拥有一个多维数据集的显示列表,并使用glColor和glTranslatef像这样(伪代码)反复调用它来更改颜色和位置:

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

通过这种方式,我可以在开始注意到帧率之前渲染大约10,000个多维数据集,这是可以的,但是我希望它更快,以便我的程序可以移植到性能较差的计算机上,所以我的问题是:

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:

什么是渲染许多相同但最有效的方法 独立的对象,我将获得比我更好的性能 现在正在使用显示列表? 我应该使用C还是学习顶点 缓冲吗?

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.

推荐答案

这就像常识是错误的.在绘制cube之后,您手动恢复了转换(glTranslatef(-x,-y,-z)),这样glPopMatrix不仅无缘无故地被调用了两次,而且因为您已经做了所有工作,所以它也没有用. 正确的代码是这样的:

It is like the common sense was wrong. You manually restore the transformation (glTranslatef(-x,-y,-z)) after drawing the cube, this way glPopMatrix 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:

for x in xrange(...):
    for z in xrange(...):
        y = height[x,z] #numpy array
        glPushMatrix() #Remember the matrix
        glTranslatef(x,y,z) #change the matrix
        glColor((r,g,b))
        glCallList(cube)
        glPopMatrix() #Restore tha matrix as it was before glTranslate changed it

这篇关于使用Python在OpenGL中显示列表的效率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆