如何在python,pygame和pyopengl中保存并重新加载渲染的模型/列表以保存启动时的加载和渲染时间?

时间:2015-04-16 13:06:30

标签: python opengl pygame pyopengl

首先,这就是我想要实现的目标:我有一个存储在文件中的渲染高度贴图对象,当我在游戏开始时打开它时,地形已经加载,节省了无数分钟加载和渲染,不计算我游戏中的所有其他对象,我会做同样的事情。

我编写了一个地图编辑器,它首先让我编辑一个地图,然后编译/渲染它,然后将编译后的地图列表保存到文件中。然后当我继续游戏时,游戏会加载文件并将列表存储到对象模板类中。

这是我在游戏启动时如何从文件中加载列表的算法:

renderedList = load_map("map.pom") # <- this would call a function which would open the file and dump it to a renderedList variable
class Obj():
    def __init__(self, renderedList):
        self.list = renderedList
    def draw(self,pos=[0,0,0],rotations=[],scalar=1.0):
        glPushMatrix()
        glTranslatef(*pos)
        if len(rotations) == 3:
            if rotations[0] != 0: glRotatef(rotations[0],1,0,0)
            if rotations[1] != 0: glRotatef(rotations[1],0,1,0)
            if rotations[2] != 0: glRotatef(rotations[2],0,0,1)
        glScalef(scalar,scalar,scalar)
        glCallList(self.list)
        glPopMatrix()
    def __del__(self):
        del self.list

Map = Obj(renderedList) # <- here I create an object which allows me to draw or delete the list to/from the screen

...
''' IN THE GAME LOOP '''
Window.clear()
Map.draw()
Window.flip()

那么如何在python,pygame和pyopengl中保存并重新加载渲染的模型/列表以保存启动时的加载和渲染时间?

编辑:我在python 2.7编程

0 个答案:

没有答案