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

Re: [pygame] Working with Surfaces



hello,

it's generally good to keep out python code from the main logic of your functions, if you can.  Then try and keep the python wrapping function to interacting with python.  That is keep the SDL parts and the python parts as separate as possible.

The python wrapper part will use a call like so...
    surf = PySurface_AsSurface(surfobj);

to get the "SDL_Surface* surf" surface, which you can then pass to your function.


Since the life time of the surface is done with python, through reference counting.  Each time you access the surface you should probably first increment a reference count, and then modify it, then decrement the reference count.  Otherwise you might want to store a reference at initialisation time, then it should be fairly safe to access the surface.

However, the display surface can disappear, so perhaps passing in a surface each time might be better.

I hope maybe that helps answer your question...


ps.  be good to start a branch in svn to dump your code as you go :)  Then we can all look at your code specifically.




On Tue, May 19, 2009 at 8:02 AM, Tyler Laing <trinioler@xxxxxxxxx> wrote:
Hello all,

I've got a bit of a brainteaser for you, maybe, and hopefully not.

Right now, through judicious use of ffplay code, I've got a large portion of the code written for a first draft version of the movie module. I changed the code where appropriate for our needs. Of course, that doesn't mean its been tested, or has even compiled yet. ;) However, I'm wondering which way I should go: Whether I should write to a pygame surface(say one passed on initialization), via the PySurface C methods, or to extract the rect and surface from the PySurface struct, and write to those instead. Which way would be safer/better/whatever?

-Tyler
Visit my blog at http://oddco.ca/zeroth/zblog