Re: [PyOpenGL-Users] Suspiciously slow script
Brought to you by:
mcfletch
From: Derakon <de...@gm...> - 2010-05-21 04:59:20
|
Thanks for the advice. I gave it a shot, and while it's an improvement...it's one of 4FPS, from 15 to 19. So clearly something is still wrong. I've uploaded the new script here: http://derakon.dyndns.org/~chriswei/temp/gltest2.py I turned off the texture cycling because it was just distracting from the matter at hand, so the program now just creates the display list and then loops, drawing it, as the camera moves about (I note that my framerate is much better when the tiles are further away from the camera). Any other ideas? -Chris On Wed, May 19, 2010 at 10:51 PM, Ian Mallett <geo...@gm...> wrote: > Hi, > > Two things are making your code slow that I notice immediately: > 1) You're using a Python loop to do 400 operations. That's not going to be > terribly fast. > 2) More importantly, you're using fixed functionality to draw 400 polygons. > > You can fix both problems by using a display list, vertex array, or vertex > buffer object. I do not recommend the latter two, as they are more > difficult (although more flexible, and also not technically deprecated). > > To use display list rendering, simply bracket the drawing code (that's > everything including the texture binding, the glBegin(...), the loops, and > the glEnd()) as follows: > > display_list = glGenLists(1) > glNewList(display_list,GL_COMPILE) > ... > #draw your stuff here > ... > glEndList() > > ...and drop the whole thing outside of your main loop (put it with > initialization). Then, to render the display list: > glCallList(display_list) > > ...and your polygons will be magically be drawn. And much faster too! > > Another tip: disable vsync to get framerates faster than 60Hz. Simply do > the following before creating the window: > pygame.display.gl_set_attribute(GL_SWAP_CONTROL,0) > > Hope this helps, good luck, and welcome to PyOpenGL. > Ian Mallett > |