[PyOpenGL] How do I save runtime on drawing HUGE polylines (120 000 vertices)?

F. GEIGER f.geiger at vol.at
Fri Jun 11 12:11:47 EDT 2004


Posted to comp.graphics.api.opengl and comp.lang.python.

Hi all,

I have to draw huge polylines.

The OpenGL Canvas' OnPaint method calls

Engine().drawShapes()


which is code of mine and looks like this:

def drawShapes(self):
    print "# shapes =", len(self._shapes)
    for S in self._shapes:
       S.draw()
    return


self._shapes isn't large, because I've stuffed all the vertices into an 
array, which then is displayed by _ShapePolyline::draw():

def draw(self):
    t = time.time()
    glBegin(GL_LINE_STRIP)
    apply(glColor3f, self._colorRGB)
    for loc in self._locs:
       x, y, z = loc[0]
       glVertex3f(x, y, z)
#   map(lambda x: glVertex3f(*x[0]), self._locs)
##### Doesn't perform much better
    glEnd()
    print "_ShapePolyline::draw(): Drawing of %d points took %s s" % 
(self._numLocs, time.time() - t)


The above print statement shows, that 5 secs are consumed for about 120 
000 (hundred-twenty-thousand) vertices. You guess, the whole GUI becomes 
  unusable.

I am forced to redraw the polyline, because of a glClear call in 
OnPaint(). W/o such a call the canvas would fill until nothing is 
recognized anymore when I rotate it with the mouse, i.e. it's filled 
with the shape's colors.

Yes, it's Python code, but I guess that's not the problem here. It seems 
to be a fundamental problem, I'm doing something fundamentally wrong.

So I wonder, do I really need to draw those 120000 vertices over and 
over again? Would glArrays perform much better? Or is this a case for 
Display Lists? Any other idea?

Many thanks in advance and kind regards
Franz GEIGER



More information about the Python-list mailing list