Warmup game: Strictly Platonic

I've only ever used plain old pygame in PyWeek, so I thought I'd look at some other libraries. Pyglet is popular, so I tried to learn that. After spending an hour trying to draw a freaking circle, I realized that you really need to understand OpenGL before you can use Pyglet for graphical primitives. So I decided to learn OpenGL instead.

I had no idea how easy it is to make a 3-D flight simulator! Okay, there's still a lot to it, but between GL_DEPTH_TEST, gluPerspective, and gluLookAt, half of the work I imagined is taken care of. Obviously, lighting and textures are huge topics for a beginner, so I decided to copy those bits from the tutorial and focus on what I know: solid geometry.

The game comes in one big file, strictly-platonic.py. I developed it on a 1.6 GHz Eee PC, so I can't imagine it running slowly for anyone, but let me know if you have any trouble or suggestions. Enjoy!

(log in to comment)

Comments

Neat!
some error messages: http://paste.ubuntu.com/256849/
i were trying on Ubuntu 9.04 i386 - please share screenshots (like placed at login-free picture hosting sites like imageshack.us)

Looks like nitrofurano has an OpenGL implementation that doesn't support non-power-of-2 textures. The OpenGL standard only requires drivers to support textures with dimensions that are round powers of 2 (and square). Using funny-sized textures is a fairly common mistake among OpenGL beginners - lots of drivers will accept it and work fine, but not all.

Fun little game though! Will you be doing something exciting and 3d for Pyweek proper?

Pyglet is a thin layer on top of OpenGL and I can heartily recommend it! It handles routine stuff like loading images and placing them into power-of-2 textures, but still lets you fiddle with triangles.
Hey, thanks for the tip, Martin! I might try some really simple 3D like this, but nothing fancy. What was the last 3D game that did well in PyWeek? Just curious.

nitrofurano, lines 477 through 480 currently read:

    data = pygame.image.tostring(s2, "RGBX", 1)
    self.texture = glGenTextures(1)
    glBindTexture(GL_TEXTURE_2D, self.texture)
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, self.x, self.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, data)
Please try replacing them with the following, and let me know if that works:
    nextpow = lambda x: min(1 << k for k in range(20) if 1 << k >= x)
    px, py = nextpow(self.x), nextpow(self.y)
    s2 = pygame.transform.smoothscale(s2, (px, py))
    data = pygame.image.tostring(s2, "RGBX", 1)
    self.texture = glGenTextures(1)
    glBindTexture(GL_TEXTURE_2D, self.texture)
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, px, py, 0, GL_RGBA, GL_UNSIGNED_BYTE, data)
It probably makes the text a little uglier, but it might let it run.

Well, both Pyweeks 3 and 5 had winning entries with 3d graphics, and I think there have been a few others that did fairly well, although obviously not as many as have done with 2d. The only entry with full 3d gameplay that springs to mind though is Alex's delta-v in Pyweek 4.

Ah yes, Bouncy the Hungry Rabbit. The graphics on that are excellent. I always meant to go back and learn how he did that. Wound Up, of course, too, but that's Super Effective. Don't take this the wrong way, but I tend to ignore your team when it comes to gauging what's possible in PyWeek. ;-) At least for an individual.

And looking back, there are a couple recent 3D entries that turned out all right. I don't need to win, but I want to make something people kinda like. I always think of 3D as a surefire way to blow the week on the engine and not get any gameplay in. Maybe it's worth a shot, though.

Hey, just letting you know that power of 2 fix worked for me! Thanks! Pretty cool demo :D. Inspires me to try this with pyglet.
Cool, thanks. It's too bad it makes the text a little harder to read, but it's better than nothing. I updated the upload in the OP, so it should work now for everyone, but let me know if there's still any problems!
Power of 2 may be supported in other OpenGL implementations but you might find that the performance hit to support it is severe, so just always aim for power-of-2 :)

pyglet's image and texture management code has support for managing non-power-of-2 texture images inside power-of-2 textures fairly automatically (ie. if you load a random image then it'll automatically be fitted into a power-of-2 texture for you, and the appropriate texture coordinates generated so you can use the correct region of that texture).

Heh. Bouncy. That was fun :) The key was using wings3d for the modelling, no textures and simple OBJ file loading. Textures (UV mapping) are hard.

@Cosmologicon - thanks, i saved your patch, and will try it asap (the computer i'm on now is too slow for that, and with an old generic 2d vesa board...)