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

Re: [pygame] PyGame / PyOpenGL Example



yeah, I think there are a couple of approaches.

Lamina takes the first approach... which is to make almost everything
work - just by updating dirty rects.  So you render to an offscreen
surface.  As long as you are careful with dirty rects - it should be
fairly fast, and not very complex.  Mainly to be able to use software
rendering in your opengl app.

However for lots of moving images, it's probably not the fastest way -
which is where your approach is better.


At one point a few years ago I tried to make a spritegl class - that
wasn't very sophisticated, but worked ok for basic games.  It's in
http://rene.f0o.com/rdpyg/ but it doesn't work on all games.  The idea
was to do it at the sprite level so you can optimize things like
drawing 20 sprites at once etc.  I found it ran mostly slower than SDL
- but it was really badly written, mostly as a prototype.  Both your
code, and Lamina are better.

It would be nice if pygame.sprite was more hardware friendly.  So
things like rotation, and scaling were abstracted.

Also note, that SDL 1.3 has pretty good opengl, and direct 3d
support... they basically use the idea of hardware surfaces for their
abstraction.  You can run some demos already, and it's interesting to
look at that API.


Also, here is some code to make opengl act like it's in 2D.  So you
can draw things using pixel coordinates, rather than 3d coordinates.

http://pygame.org/wiki/MakeOpenglDrawIn2D

def glEnable2D():
    """ make opengl behave like you are drawing in 2d.    """
    vPort = glGetIntegerv(GL_VIEWPORT)
    glMatrixMode(GL_PROJECTION)
    glPushMatrix()
    glLoadIdentity()
    glOrtho(0, vPort[2], 0, vPort[3], -1, 1)
    glMatrixMode(GL_MODELVIEW)
    glPushMatrix()
    glLoadIdentity()



def glDisable2D():
   """ Use when you've finished drawing in 2D.   """
   glMatrixMode(GL_PROJECTION)
   glPopMatrix()
   glMatrixMode(GL_MODELVIEW)
   glPopMatrix()





cu,


On Feb 14, 2008 12:22 PM, Brian Fisher <brian@xxxxxxxxxxxxxxxxxxx> wrote:
> On Feb 13, 2008 3:43 PM, René Dudfield <renesd@xxxxxxxxx> wrote:
> > Have you seen the Lamina code?
> > http://pitchersduel.python-hosting.com/browser/branches/Lamina/
> >
> I hadn't seen it before - It appears to take the approach of
> maintaining a single full-screen overlay which is created from a
> pygame surface. I would guess that it would perform poorly if you
> wanted a lot of moving/animating pygame surfaces drawn all over. Also,
> it appears to take the approach of putting the overlay into a subset
> of a power of 2 texture.
>
>
> > 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).
> >
> It sounds fun to write something like that up - should the goal be
> something that is close to a drop in replacement for pygame.display
> stuff? maybe with some additional interface for getting transformed
> and colored blits or something?
>