Jump to content

  • Log In with Google      Sign In   
  • Create Account

Recommendation: pyglet library for Python


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
24 replies to this topic

#1 Kylotan   Moderators   -  Reputation: 3338

Like
0Likes
Like

Posted 20 December 2007 - 10:29 AM

I've been looking for an alternative to PyGame for some time, and finally I can say I've found it. The problems with PyGame are two-fold: first, that it's poorly maintained, and second, that it relies on SDL which - although well tried and tested - is also poorly maintained, and getting quite long in the tooth as a result. Today I finally got around to trying pyglet, and it seems to be a more than adequate replacement for PyGame. I'm always in favour of getting more people to use Python, so they can spend their time making the games they want to make instead of wrestling with the intricacies of C++, and pyglet looks like the best choice currently, for these reasons: - BSD open-source license, good for almost any project, commercial or not; - runs on Windows, Mac OS X, and Linux, with a decent installer for Windows at least; - Uses OpenGL natively for rendering, not DirectDraw, GDI, or some other slow and/or old approach; - Great documentation, including a very readable Programming Guide plus seemingly accurate API docs; - various cool things built in, such as text rendering, playing of streaming audio and video, z-ordering of blits, sprite sheets, all accomplishable in under 10 lines of code. Here, have an OpenGL-accelerated bouncing ball program:
from pyglet import image
from pyglet import window

# Set these to the size of your background image
win = window.Window(width=768, height=768)

# Set these paths to a couple of graphics
ball = image.load('some_small_image.png')
background = image.load('some_background.jpg')

ball_coords = [0,0]
ball_velocity = [5,3]

while not win.has_exit:
    win.dispatch_events()
    
    ball_coords[0] += ball_velocity[0]
    ball_coords[1] += ball_velocity[1]
    
    if ball_coords[0] > win.width - ball.width or ball_coords[0] < 0:
        ball_velocity[0] = -ball_velocity[0]
    if ball_coords[1] > win.height - ball.height or ball_coords[1] < 0:
        ball_velocity[1] = -ball_velocity[1]
        
    win.clear()
    background.blit(0, 0)
    ball.blit(*ball_coords)
    win.flip()    


All you need to run this is to install pyglet (which requires Python 2.5, or Python 2.4 with ctypes installed), save this as a .py file, ensure you have 2 images in the same directory with the names you supply in the code, and run it. If you want to verify that it's using OpenGL, add "from pyglet import gl" at the top and add "gl.glColor3f(1.0, 0.0, 0.0)" just before background.blit(), and see what you get. It's not perfect yet though: you have to use low-level OpenGL calls to get anything advanced done (eg. glEnable(GL_BLEND) followed by glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) if you want alpha blended sprites), the sprite interface is a bit bare right now (though allegedly this is where Rabbyt comes in), and sound support on Linux seems a little ropey if the docs are accurate. Hopefully nobody minds me posting this; it's not my project and I don't stand to gain anything. I'm just quite excited at Python becoming a more viable platform for our games. Comments and criticisms welcomed, of course.

Sponsor:

#2 Oluseyi   Staff Emeritus   -  Reputation: 1678

Like
0Likes
Like

Posted 20 December 2007 - 10:43 AM

Pretty cool. Someone mentioned Pyglet on #gamedev a day or two ago. I'll probably install it and play around with it over the weekend. I like to stay on top of all Python-related developments.

This also reminds me to look into PyPy, IronPython maturity (and suitability for eventual Managed DX/XNA/SlimDX programming), and StarKiller (is it still alive?). If you can develop Silverlight applications in IronPython...

#3 GMuser   Members   -  Reputation: 211

Like
0Likes
Like

Posted 20 December 2007 - 12:50 PM

I have also recently gotten into pyglet. I always wanted to make games in python, but I thought my only option was pygame which just seemed too bloated for my tastes.

In my opinion, it is a lot easier to learn (the supplied tutorial tells you what you want to know- and you are not overwhelmed by overly lengthy descriptions of things you would already know if you have ever programmed a game before) than pygame. The included OpenGL support is great (I personally have never used OpenGL before- I am going through the nehe lessons), there isn't any fiddling around with a variation of the commands which you are left to figure out on your own. And the fact that it is included and incorporated into the entire design of the engine makes it very much easier to get into, as opposed to the pygame+PyOpenGL combination of doom.

I definitely recommend this also!

#4 Megaman_22   Members   -  Reputation: 100

Like
0Likes
Like

Posted 20 December 2007 - 02:20 PM

Can you recommend any more advanced tutorials than the bare-bones ones in the Programming Guide?

#5 GMuser   Members   -  Reputation: 211

Like
0Likes
Like

Posted 20 December 2007 - 02:56 PM

What kinds of things are you after exactly?

#6 Megaman_22   Members   -  Reputation: 100

Like
0Likes
Like

Posted 20 December 2007 - 05:34 PM

Something along the lines of the chimp game tutorial on the pygame site would be nice to see. I didn't dig all that deeply into the pyglet programming guide, into all the nitty gritty details of the implementation. But the five-odd example programs in the "Writing a pyglet application" section were kind of trivial.

Wait, never mind, I see there's some example programs in the downloadable documentation.

#7 Kylotan   Moderators   -  Reputation: 3338

Like
0Likes
Like

Posted 20 December 2007 - 11:31 PM

The fundamentals of game development apply pretty much equally to PyGame, pyglet, and any other similar library. The important stuff is how you handle the input and output, and I believe the documentation is very good for that.

#8 treeform   Members   -  Reputation: 122

Like
0Likes
Like

Posted 21 December 2007 - 09:05 AM

Panda3d:

panda3d

Has far more features then pyglet. Its also coded with python. Python is he first class citizen while the engine is written in c++. It can be extended with c++ for speed because python does get slow.

It has your basic and advanced scene graph stuff nodes,instances,rigid body combiners,transparency sorting, view ports.

It has build it physics and collision system (ODE is being integrated as well as roots Physx and Newton)

It has extensive sound support (fMod and openAL)

It has actor animation morphing and stuff (I am not shure about bones - i deal with spaceships)

It has shaders with post processing - which i use alot.

It even has a network library and a patching system for those who want to build a mmo.

Runs on linux an mac as well as that other OS. (also mac support is a little behind - you have to build yourself - while linux support is high quality with) I develop on linux and it runs every where

It has many other things ...

Some images from my mmorts project (
aff:2aw) can be found here :
screenshots of what is possible with panda3d

[EDIT: removed screenshots as they were a bit big for the thread. If you want to repost smaller ones, be my guest -- Kylotan]

[Edited by - Kylotan on December 22, 2007 6:05:24 AM]

#9 Knarkles   Members   -  Reputation: 271

Like
0Likes
Like

Posted 21 December 2007 - 10:17 AM

Today I implemented a Pyglet window manager plugin for my engine, and I love it! Much cleaner than Pygame overall. I might finally let Pygame go, after a long time of not really being happy with it...

#10 dbaumgart   Moderators   -  Reputation: 142

Like
0Likes
Like

Posted 21 December 2007 - 01:19 PM

Damn! Here I am with a half-built Pygame engine and you come along with this. Oh, all the pain Pygame has caused me -- and it's finally coming together!

You've pretty much already got me sold but I'm going to specifically not use Pyglet until I'm ready to build my next game, otherwise I'd be forced to re-do my whole engine in it and drive myself crazy again.

#11 Oluseyi   Staff Emeritus   -  Reputation: 1678

Like
0Likes
Like

Posted 21 December 2007 - 02:15 PM

Quote:
Original post by dbaumgart
You've pretty much already got me sold but I'm going to specifically not use Pyglet until I'm ready to build my next game, otherwise I'd be forced to re-do my whole engine in it and drive myself crazy again.

Wise choice.

By the way, I've been enjoying your journal very much!

#12 Kylotan   Moderators   -  Reputation: 3338

Like
0Likes
Like

Posted 22 December 2007 - 12:35 AM

Quote:
Original post by treeform
Panda3d:

panda3d

Has far more features then pyglet.


Panda3D is quite impressive, but it's not really comparing like-with-like - you could also be comparing Python-Ogre, for example. It looks good for 3D work though. Bit of a shame the license is a bit odd, however.

#13 mrbastard   Members   -  Reputation: 1573

Like
0Likes
Like

Posted 22 December 2007 - 12:57 AM

Sounds cool. I'll probably move my PyGame experiments with steering behaviours over to Pyglet over the holiday.

I'm actually quite glad low-level OpenGl is part of the equation - means I can use all my existing OpenGL stuff, once I've applied a little boost.python magic fairy dust.

#14 Barius   Members   -  Reputation: 325

Like
0Likes
Like

Posted 22 December 2007 - 12:58 AM

The problem with OpenGL and libraries that use it is that if you don't have working hardware acceleration, you're out of luck. The bouncing ball example runs at a whopping 4FPS here using software rendering (Linux/Mesa). If you're making a simple 2d game, consider that some people play 2d games *because* they don't require special hardware / drivers.



#15 Kylotan   Moderators   -  Reputation: 3338

Like
0Likes
Like

Posted 22 December 2007 - 01:07 AM

Well, it's definitely a choice people will have to consciously make. What's important to me at this stage is that with the hardware now commonly available for 10 years, we should be able to take advantage of it easily.

#16 OrangyTang   Members   -  Reputation: 1294

Like
0Likes
Like

Posted 02 January 2008 - 01:22 AM

Quote:
Original post by Barius
The problem with OpenGL and libraries that use it is that if you don't have working hardware acceleration, you're out of luck. The bouncing ball example runs at a whopping 4FPS here using software rendering (Linux/Mesa). If you're making a simple 2d game, consider that some people play 2d games *because* they don't require special hardware / drivers.

Even the lousy intergrated intel chipsets have enough oomph to push around a few textured quads, and will have drivers preinstalled. If you can't be bothered to install suitable drivers for your own linux box thats your own problem.

#17 NineYearCycle   Members   -  Reputation: 962

Like
0Likes
Like

Posted 08 January 2008 - 11:22 AM

@kylotan
I currently have your logo bouncing around a screenshot from your demos on your site with alpha blending working, this python stuff is fun! I call it KYLO_BALL! ;)

Andy

#18 eedok   GDNet+   -  Reputation: 971

Like
0Likes
Like

Posted 01 February 2008 - 07:21 AM

finally got around to checking this out, but lack of joystick support kind of killed it for me, which is too bad as I'm still looking for a cross-platform game library that supports joysticks and rumble among other needs.

#19 Kylotan   Moderators   -  Reputation: 3338

Like
0Likes
Like

Posted 01 February 2008 - 01:24 PM

Apparently you can use the input handling from Pygame and stick with Pyglet's rendering and everything else if you want. Not ideal though, I admit. :)

#20 Boder   Members   -  Reputation: 917

Like
0Likes
Like

Posted 01 February 2008 - 03:15 PM

Yeah, I've been interested in the number of creation libraries/engines/tools using scripting languages. Some to check out.

Pycap (tuxcap on linux) for the Popcap Framework
Fenix (uses its own language)
Novashell/Agen (both use Lua and both early in development, Agen more so)




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS