Friday, August 31, 2007

pyglet and pygame: which one?

Pygame is great. Pete Shinners has done some fantastic work in creating it. I have played a bit with it in the past and was planning to learn to use it better, and probably write some Crunchy-based tutorials for it. Unfortunately, this will not happen. Since I moved from a PC to a Mac, and installed Python 2.5, I can not use Pygame, as there is no ready-made version for my setup. Yes, I imagine I could find out how to compile it from the source ... but there is an easier alternative: pyglet. pyglet is a pure python library, with no external dependency. I downloaded it, tried it ... and it just worked. Not only that, but when Python 2.6 will come out, I know it will still work.

I do realise that pyglet is just in alpha stage ... but it's a very impressive alpha. It is not as fully featured as Pygame is ... but it works for me, thanks to Alex Holkner.

If you're currently using pygame, there's probably not any reason to switch. But if, like me, you find that you can not use pygame with your current setup, check out pyglet. You might be pleasantly surprised.

9 comments:

illume said...

Hi,

there are instructions on compiling pygame on macosx here:
compile pygame on macosx

The new release of pygame 1.8 will have a python2.5 download. I'll try and make a download before then though.


Cheers,

Brian Jorgensen said...

Pyglet is awesome! I used it to implement 2d/3d plotting functionality for SymPy (a python CAS library) over the summer, and will be using it for PyWeek 5 (starting tomorrow).

As I've worked with it, I've found it to be well designed and very easy to use. Since it provides its own OpenGL wrapper, you can simply import the pyglet directory into your project and then distribute it with no external dependencies (other than ctypes, which is included with Python 2.5).

Although you can do OpenGL in Pygame, it is built on SDL (another dependency) and so it focuses on a 2d framebuffer model, which IMHO is an anachronism. Pyglet, on the other hand, is built on OpenGL while still providing great 2d sprite support. Also, pygame development has slowed to a crawl, where pyglet development is very active.

I would encourage existing pygame users to check it out!

Red15 said...

Can you tell a bit about performance ? Being all native python will have it's benefits I am sure, but it also worries me if the blitting s performed inside python code or a separately compile module or whatever you wanna call it.

André said...

red15:

I am not an expert ... but from what I understand, pyglet is essentially using ctypes to wrap some opengl functions - it is fast. I don't have any comparisons with pygame but I recall seeing a demo at Pycon 2007 that was as fast as anything else I had seen.

Nathan said...

I independently discovered pyglet three weeks ago while trying to get pygame to work under OS X Leopard.

I've since converted to pyglet and not looked back.

Mike Lawrence said...

I was introduced to python via pygame and loved it, but also was annoyed to find it somewhat incompatible with the default python 2.5 install that comes with Mac OS X Leopard. I've thus moved to pyglet and found it a completely sufficient replacement for my purposes (I design cognitive science experiments) EXCEPT for the lack of Joystick interface.

André said...

An anonymous author posted the following (now deleted) comment, slightly edited:
====
Pygame is (deleted; read "disappointing").

Its June 19th 2008 and still no prebuilt binaries or dmg installations for Mac OS X.

Only go try this build method or this patched up release candidate version or better yet they now point you to Mac Ports and the pygame there (once you can find it) has Python 2.4 requirement. The "Place other than Heaven" with Pygame. I've bought all the Pygame books and really got into it but I am now switching to Pyglet and not looking back.

Very disgusted Mac User.
======
While I agree somewhat with the general thought expressed, which makes me prefer pyglet, I think it is important to remember that the work is done by volunteers, and nothing prevents anyone from joining and helping.

Pierre-Alain Dorange said...

@andré

pygame got an installer for Python 2.5.
I began using python/pygame few month ago and i used pygame 1.8 for Python 2.5
As i used MacOS X 10.4 i also have to install Python 2.5.

http://rene.f0o.com/~rene/stuff/macosx/
i go tthe link from pygame web site.

It works very fine on my intel iMac.

André said...

@Pierre-Alain:

Merci!