tricks for good 2d rendering performance with pygame

Oct 23, 2010 16:35


pygame's API for initializing a display has a couple attractive sounding flags. Or at least, they sound attractive once you notice that updating your 320x240 window at 30fps is consuming all available cycles on your brand new Intel i9 CPU. They're HWSURFACE and DOUBLEBUF. Hardware surfaces and double buffering is how you make graphics fast, ( Read more... )

python, performance, pygame

Leave a comment

Comments 8

image = image.convert() ext_27280 October 24 2010, 10:18:41 UTC
If you don't specify a format for convert(), it picks the one most suitable for blitting to the display surface. I.e. there's no need to manually check bit depths.

Reply

Re: image = image.convert() jcalderone October 24 2010, 22:09:53 UTC
Eugh. Good to know. Though this begs the question why pygame.image.load doesn't just pick the most suitable depth. :) I suppose it has something to do with the fact that you can load an image before you initialize the display, but you can't convert an image until after you initialize the display. But then, why that arbitrary difference?

Reply

Re: image = image.convert() foone October 25 2010, 11:39:45 UTC
Probably because you might want to do something with an image other than blit it (also there's two ways to convert: .convert and .convert_alpha, picking either to be automatic would annoy people who want the other behavior), like say if I want to load a greyscale image to use as a heightmap: I'd like it to stay as a 8bpp image, not get converted to 32bpp because the user happens to be using a 32bpp display.

Reply

Re: image = image.convert() jcalderone October 25 2010, 19:05:26 UTC
I suppose. I probably wouldn't use the pygame image loading APIs for images I didn't intend to eventually blit, but maybe your explanation still makes sense in general.

Reply


glyf October 25 2010, 18:49:42 UTC
Is there any way to detect that some of your surfaces are in the wrong format, other than the performance hit?

Reply

jcalderone October 25 2010, 19:04:25 UTC
I'm not aware of any way (but that doesn't mean a _whole_ lot).

Reply


pyglet? anonymous November 1 2010, 23:34:19 UTC
Hey, why use pygame when there's pyglet?

dotz

Reply

Re: pyglet? jcalderone November 2 2010, 01:36:48 UTC
Partly because I started the project before pyglet was around (or at least before it was as usable as it is today).

And partly because it's still not clear to me how to do networking with pyglet without re-implementing its three platform-specific event loops.

Reply


Leave a comment

Up