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) 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? nitrofurano, lines 477 through 480 currently read:
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. 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.
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.
Comments
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.
richard on 2009/08/21 03:57:
Neat!