我的问题是,我的程序显示一个带有120 fps限制的简单多维数据集,只能运行25 fps。我发现所有的性能损失都在OpenGL部分,但我不知道确切的位置。
我的问题是:
下面是我用于显示多维数据集的代码:
def draw(self):
glBegin(GL_QUADS)#info for OGL: treat following code as surface drawing code
for surface in self.surfaces:
x = 0
for vertex in surface:
x+=1
glColor3fv(self.colors[x])
glVertex3fv(self.verticles[vertex])
glEnd()
glBegin(GL_LINES) #info for OGL: treat following code as line drawing code
for edge in self.edges:
for vertex in edge:
glVertex3fv(self.verticles[vertex]) #pass each verticle in the verticles list to glVertex3fv, which creates edges
glEnd() #info for OGL:no more code incoming发布于 2015-10-03 10:28:12
不,OpenGL运行这么慢是不正常的。这里的慢点来自于使用即时模式(glBegin(),glEnd())。基本上,您调用这些python命令的每个帧都必须立即生成输出。这在C中是慢的,更不用说Python了,它是逐行解释的。
您需要的是预先准备顶点缓冲区(通常称为VBO),然后在渲染时将它们提交给批处理呈现。
看看这个现代OpenGL (>=2.0)方法的wikibook:Introduction。它是用C/C++编写的,但是您可以遵循函数调用和原则。
https://stackoverflow.com/questions/32921445
复制相似问题