To main page | 3dengine.org

glCallList PyOpenGL Template



This is only partial example, for a better class, see CallList PyOpenGL Class.



This is a template to use for cached drawing with call lists in PyOpenGL:
def __init__(self)
    self.call_list = glGenLists(1)
    self._invalidated = 1
def __del__(self):
    if glDeleteLists is not None: glDeleteLists(self.call_list,1)
def draw(self):
    if not self._invalidated:
        glCallList(self.call_list)
    else:
        self._invalidated = 0
        glNewList(self.call_list, GL_COMPILE_AND_EXECUTE)
        glBegin(GL_...)
        ... do actual drawing here ...
        glEnd()
        glEndList()
Set self._invalidated to 1 wheneven you need to update cache

PyOpenGL is very slow at GL calls - every call is an dictionary lookup, then all those error checks, etc. Call lists are a way to avoid it. In fact call list for a million points executes as fast as if it were called from C.