[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] Pygame and OpenGL



On Mon, 5 Nov 2001 crispin@iinet.net.au wrote:

>On Mon, Nov 05, 2001 at 09:56:47AM +0200, Jan Ekholm wrote:
>> 
>> Hi all,
>> 
>> Played some with the PyOpenGL package, and it even has some context for
>> use with pygame. What I'd like to do, however, is just use pygame as
>> normally and use a small surface for all OpenGL. Is it possible to combine
>> those two? I don't want to do normal pygame rendering on the OpenGL
>> surface, but would like to eventually blit the OpenGL surface onto the
>> screen, on top of the normal pygame "toplevel" surface. 
>> 
>> Not that this really is important, I'm just curious to see how it works if
>> at all. :)
>
>I have used pygame and pyopengl together. Its entirely doable, but the
>speed slug will kill your game. My advice would be to use OpenGL as your
>whole graphics system. Its faster when accelerated than SDL. If you want
>to do 2D gfx with it then use OpenGL with Ortho projection. You can
>switch between ortho and perspective projection matricies if you need
>to.

This was a bit what I suspected. I've just come to like pygame's 2D
graphics a lot. For stuff like a status panel that gets updated frequently
I think a 2D toolkit would be the best. That's why I'd want to combine the
two, but I understand your argument that this might kill the speed. When
going 3D with Python I assume one wants all acceleration that's available.

>You can also do texture weighting and other cool gfx memory management
>in OpenGL 1.1
>
>I have used the pygame routines to render things to a SDL surface, then
>used the Image's tostring() to turn it to a raw string to be imported
>into a GL texture.

Hmm, how well would this work for frequently changing data that changes,
say, once every second? I assume that the best way is still to get a panel
and other status data done as normal textures blitted in glOrtho, as you
said. It's a little bit more work to maintain those textures than would
normal 2D pygame graphics.

Hmm, does anyone have a really simple pygame-based application that just
creates a OpenGL surface and draws something really simple on it? I'm not
sure the pygame contexts that come with pyopengl are what I want. I have
the impression I can simply do something like:

# create an OpenGL surface
surface = pygame.display.set_mode ((width, height), OPENGL | DOUBLEBUF)

# render stuff onto it
glBegin ( GL_TRIANGLE )
glVertex (...)
glVertex (...)
glVertex (...)
glEnd ()

# update display
pygame.display.flip()

Is this possible? Is the surface 'current' when it's created? I assume I
can't really have multiple surfaces, as they'd be offscreen, and thus
suffer the dramatic performance hit?

Thanks a lot for the help, I'm now one step closer to a simple test
application.

-- 
               "Stercus, stercus, stercus, moriturus sum."
                                       -- Terry Pratchett, Interesting Times


____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org