pyglet week 3 : Some Pretty Flowers

This is just a refinement of last week’s script. No massively significant changes, just a bunch of minor tweaks.

  • The fans are replaced with slightly prettier flowers, with separate vertex and color arrays for each one.
  • Running with the python -O flag means we can render 800 flowers at 30fps, no problem.
  • The camera can now be moved and rotated and zoomed. I just use this to subtly zoom in after the screen has filled with flowers
  • I discovered that if I fail to clear the screen before rendering, then I inherit the appearance of the desktop as a backdrop. No doubt this cannot be relied upon, and presumably doesn’t happen on some other graphics hardware or operating systems, so YMMV (Update: yep – it looks CRAZY on Windows unless you uncomment the glClear() call). I won’t be relying on this trick in future, but for now, on my machine at least, it looks like this:

flowers1

flowers2

flowers3

flowers4

flowers5

flowers6

gameloop2c-flowers.pyPython file

10 thoughts on “pyglet week 3 : Some Pretty Flowers

  1. Cheers for writing these articles – really good stuff.

    Just for giggles I popped psyco in and it stabilized out at ~62fps vsync disabled (ati 4850)

  2. Pingback: tartley.com » Blog Archive » pyglet week 2: Better Vertex Throughput

  3. @very nice: Hey, thanks. It doesn’t really draw to the desktop, it’s just a regular fullscreen app. However, I never clear the buffer before drawing to it, and on my video card under Linux, that meant my OpenGL buffer was apparently originally filled with the image from my desktop (which is also OpenGL accelerated.

  4. Very nice one!
    how to draw to Desktop like you did ? Which flag in window to do it ? When i run urs , it only goes using own window.

  5. Thanks to everyone who’s commented, it’s a real inspiration to hear about others playing around with the same stuff.

    Jay: I agree that the hardware-accelerated ‘windowless window’ application sounds amusing. I’m not sure how I’d go about it, and would be very interested tohear how you get on.

    Personally, I’d like to try and fix the garish flashing error in my application above, by grabbing a snapshot of the desktop at startup, and blitting that into the background for each frame (instead of the glClear() call.) This then opens up cool possibilities – you could zoom or rotate the desktop image, which I image might make for a cool ‘intro animation’ as an application starts up.

    Sadly that idea’s temporarily on the back burner while I investigate generating a 2D game world, by tessellating the plane with polygons to create a large game world, with some polygons missing to create tunnels and rooms, in which entities like the ‘flowers’ above will grow and crawl around. Plus, visiting PyCon this week. And getting married. Um…

  6. I’ve enjoyed these examples as I’ve just started trying to do something with python & graphics programing myself (with much to learn).

    I’m particular interested in being able to create a pyglet “window-less” window. Something like the old Windows 3.1 cockroaches that would scuttle from window to window, i.e. a pyglet program without limits.

    Or something like an intentional version of the “desktop window” artifact you’ve been getting, maybe you can drape some flowers across window bars.

    Good luck with the wedding!

  7. In windows on a Dell laptop with ati mobility video (m3 I think), I get 11.3 fps without -O and 19ish with -O at first then moving up to close to 25fps once it has zoomed significantly, and even up over 30 at times when there is very little on the screen other than large bits of flower.

    It starts with the crazy flashing as well.

    Thanks for posting these articles, more would be exciting to see.

  8. Thanks jseb. I’ve just seen the same crazy flashing on my Windows machine at work. I was wondering if I could get around it by grabbing a snapshot of the desktop when we start, and explicitly writing that image to the background when we render? That would also let us do some fun things, like subtly zoom or rotate the desktop as we go. I’d love to try this out, but am in the thick of a different idea for next week’s post (tiling the plane to create a 2D game world.)

    I wonder why it is so slow on your machine. Maybe I’m doing something foolish that stops pyglet from correctly hooking up with the hardware acceleration, so it all ends up being software rendered? I wonder if I could print out some diagnostics on startup which might detect that situation? Hmmm…

  9. Hello,

    Nice but two problems!

    1) don’t make the assumption that the memory buffer at init will be at a given state. On my computer, there is a very unpleasant flashing at initialisation, before flowers conquers all :)

    2) it’s really slow on an Athlon 2000+, with gforce4MX CG. 6 fps in the worst case. If i use “-O” flags, it’s 12 fps in the worst case. Alas, i don’t know python, and have no idea about how it could be speed up.

    But dont give up and continue this serie of article about pyglet, it’s interesting!

Leave a Reply