[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] PyGame / PyOpenGL Example



Very cool :)


Have you seen the Lamina code?
http://pitchersduel.python-hosting.com/browser/branches/Lamina/

btw, I had to comment out this line, which seems to be fcked on
pyopengl cvs.  Otherwise it segfaulted.
        #print glGetString(GL_EXTENSIONS)

I also get this on exit:
Exception exceptions.TypeError: "'NoneType' object is not callable" in
<bound method TexturePack.__del__ of <__main__.TexturePack instance at
0x2b2a8f0>> ignored


It'd be nice to be able to get one of these into the pygame
examples... or onto the cookbook.  Especially if it can be used to run
existing games (with a little modification).



cheers,




On Feb 14, 2008 10:14 AM, Brian Fisher <brian@xxxxxxxxxxxxxxxxxxx> wrote:
> attached is an example of one way to draw pygame surfaces in OpenGL.
> It's originally a piece of a larger library, so I tried to rip out
> dependencies on that library. It exports a "Display" class which takes
> over creating the pygame display and can blit objects which have 4
> attributes on them - surface (pygame surface), width, height and
> hotspot (2 element sequence saying where the center of the image is).
> When things are blit, the Display class adds attributes to the object
> to track GL texture info. If you run it, it shows itself working (if
> __name__=="__main__": thing)
>
> It doesn't show how to print text (my class for that was too hairy to
> extract) but the approach I take is to have pygame.font render
> individual characters from strings to surfaces as needed and store
> them in dict (so they won't be regenerated all the the time), and then
> blit the cached surfaces for each letter in the string to the display
>
> There are 2 somewhat unusual things about this code - first is it
> uploads the textures as "premultiplied-alpha" or what it calls
> Light-Opacity model, where the blend mode is GL_ONE,
> GL_ONE_MINUS_SRC_ALPHA - the reason for that is that its the only way
> to get GL's bilinear filtering math to be accurate (so you don't
> introduce edge artifacts by blending color's that are supposed to be
> transparent - the yellow blocks in the exampleGL.py would have brown
> edges if it used Color-Opacity RGBA). The other weird thing is it has
> some 2d motion blur stuff.
>
> ... Also, I have to say that at first I thought it would be a "Royal
> Pain" to have to deal with rendering 2d stuff in openGL - but it
> actually turned out to be much easier than I thought and kind of a lot
> of fun (although I may have more pain later I suppose). The only thing
> that isn't trivially simple, in my opinion, is figuring out how you
> want to deal with texture size limitations. In particular, on the
> majority of systems out there, textures have to be a power-of-2 in
> width and height - so you have to deal with that to upload say a 24x12
> image for blitting. The 3 basic approaches are:
> 1. overallocate textures and render just the portion of the texture
> that has an image (so that 24x12 image would be on a 32x16 texture and
> would render just texcoords (.0,.0)-(.75,.75)), which will waste about
> 50% of your video memory and possibly cause extra texture thrashing,
> but actually some commercial games ship this way cause it just never
> ended up being a problem for their game.
> 2. spread images across multiple textures and draw all of them (so the
> 24x12 image would be spread across 4 textures, a 16x8, an 8x8, a 16x4
> and an 8x4) which lets you draw more polys in order to not waste so
> much video memory
> 3. pack multiple images into a single texture - the attached example
> uses that approach. It can be pathologically bad in terms of memory
> thrashing in some cases (like say if you wanted to draw one image each
> from 100 large multi-image textures) but if images that are used
> together are in a texture together, it is actually the optimal
> approach in terms of performance (like it tends to be good to make
> sure font characters are all packed in textures together)
>
> I hope the example helps - also I'm interested in ways people think
> this code could be improved.
>
>
>
> > On Tue, 12 Feb 2008 23:23:49 +1030, fragged <my.old.email.sucked@xxxxxxxxx>
> > wrote:
> > Hey guys,
> >
> > I've been searching for some decent examples of PyOpenGL to help me port
> > my current application to OpenGL to speed things up on my perty new
> > 1920x1200 LCD (Getting about 20fps, using no acceleration whatsoever),
> > however I've been unable to find any decent guides on the net that
> > simply show me how to do the equivalent of loading an image and some
> > text - the small fragments I have found have still been using PyGame to
> > render text and this seems to break on my gentoo system whilist working
> > on another and I'm not really sure if this is the /propper/ way to do it.
> >
> > would somebody have one of these laying about, know of one or be able to
> > hack one up for me? It'd be a great help and I'd also love to see it go
> > in the examples directory on PyGame.org as there seems to be very few
> > extreme beguinners guides.
> >
>