Re: [pygame] C access to SDL surfaces
Thanks. I'll try these out when I get a chance, and gladly make a module for it if possible, as Rene suggested. Though, I suspect it wouldn't be all that useful. Since it's a C/Python interface, and not just functionality, a module encapsulating my work might not make sense. I think it would be more of a Pyrex file, which i'd put on the Wiki. Thanks again.
Re: [pygame] C access to SDL surfaces
Pete Shinners wrote: The code should look similar to this... #include import_pygame_surface(); // Only once at startup time But note that if you use Pyrex and external extension types, you won't have to make that call. Pyrex has its own, automatic way of dynamically linking with imported types. -- Greg Ewing, Computer Science Dept, +--+ University of Canterbury, | Carpe post meridiem! | Christchurch, New Zealand | (I'm not a morning person.) | [EMAIL PROTECTED] +--+
Re: [pygame] C access to SDL surfaces
Lenard Lindstrom wrote: The pygame headers are installed in a pygame directory within the python headers directory. So it would more likely be #include Yes, this is the way.
Re: [pygame] C access to SDL surfaces
Pete Shinners wrote: Pygame has a complete C api that can be used to pass objects back and forth between Python. Your C code will need to link to Python and SDL. Then include the pygame.h After that, working with Pygame objects in C is no different than working with any other Python object in C. This is exactly what you want, but there's not much documentation on it all. the Pygame header file isn't too big though and includes many more notes. It will look funky funky because it uses Python runtime linker. The code should look similar to this... #include The pygame headers are installed in a pygame directory within the python headers directory. So it would more likely be #include unless the pygame headers path is explicitly included in the compiler search path. -- Lenard Lindstrom <[EMAIL PROTECTED]>
Re: [pygame] C access to SDL surfaces
Dan Krol wrote: My name is Dan. I'm currently developing a 2d engine, and I was wondering if I could get some help from this list. I was going to use Python only for some parts of it, but for prototyping I started making the whole thing in Python, and thus Pygame. Now I'm thinking I might just want to make most of the final version in Python, and just optimize things in C (if it's fast enough, why not?), including continuing to use Pygame. Pygame has a complete C api that can be used to pass objects back and forth between Python. Your C code will need to link to Python and SDL. Then include the pygame.h After that, working with Pygame objects in C is no different than working with any other Python object in C. This is exactly what you want, but there's not much documentation on it all. the Pygame header file isn't too big though and includes many more notes. It will look funky funky because it uses Python runtime linker. The code should look similar to this... #include import_pygame_surface(); // Only once at startup time // Create an SDL Surface and convert to a Python object SDL_Surface* sdlSurface = SDL_CreateSurface(0, 640, 480, 32, ...); PyObject* pySurface = PySurface_New(sdlSurface); // Get the SDL surface from Python SDL_Surface *surf; PyObject *anyPyObject = ...; if (PySurface_Check(anyPyObject) { surf = PySurface_AsSurface(anyPyObject); } else { surf = NULL; } You'll find functions for converting between surfaces, rects,
Re: [pygame] C access to SDL surfaces
Hi, if you think they'll be useful for other people you could maybe contribute them as a module for pygame? Or part of an existing module. Otherwise... Gregs suggestion should work fine. Cheers, On 10/17/07, Dan Krol <[EMAIL PROTECTED]> wrote: > Hello, > > My name is Dan. I'm currently developing a 2d engine, and I was > wondering if I could get some help from this list. I was going to use > Python only for some parts of it, but for prototyping I started making > the whole thing in Python, and thus Pygame. Now I'm thinking I might > just want to make most of the final version in Python, and just > optimize things in C (if it's fast enough, why not?), including > continuing to use Pygame. > > Part of the C optimization would be generation of visual effects. I > looked for this online and on the Pygame site but was unable to find > anything about it. I was wondering if someone could tell me if there > was any way to get C access to SDL surfaces. I know that there's this > Surfarray thing, but I'd rather generate my effects the old fashioned > way. > > Is there a relatively straightforward way to do this? My intention is > to make a .h file in C that generates the effect, and make it into a > python file using Pyrex. > > Thank you in advance, and thank you for offering this mailing list, > > Dan >
Re: [pygame] C access to SDL surfaces
Dan Krol wrote: I was wondering if someone could tell me if there was any way to get C access to SDL surfaces. My intention is to make a .h file in C that generates the effect, and make it into a python file using Pyrex. If you look into the PyGame sources and find out how they wrap an SDL surface as a PyGame 'surface' object, you should be able to declare 'surface' as an external extension type in Pyrex and get access to all its internals. -- Greg
[pygame] C access to SDL surfaces
Hello, My name is Dan. I'm currently developing a 2d engine, and I was wondering if I could get some help from this list. I was going to use Python only for some parts of it, but for prototyping I started making the whole thing in Python, and thus Pygame. Now I'm thinking I might just want to make most of the final version in Python, and just optimize things in C (if it's fast enough, why not?), including continuing to use Pygame. Part of the C optimization would be generation of visual effects. I looked for this online and on the Pygame site but was unable to find anything about it. I was wondering if someone could tell me if there was any way to get C access to SDL surfaces. I know that there's this Surfarray thing, but I'd rather generate my effects the old fashioned way. Is there a relatively straightforward way to do this? My intention is to make a .h file in C that generates the effect, and make it into a python file using Pyrex. Thank you in advance, and thank you for offering this mailing list, Dan