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

Re: [pygame] Changing an SDL Surface into a pygame.Surface



No, this is a good question, as the api is not documented. Documenting it is on my todo list (if I remember :-).
 
Include "pygame.h" in you extension module. The pygame headers are added to the Python headers, in the 'pygame' subdirectory. So
 
#include "pygame/pygame.h"
 
should work. If not, then add the pygame directory to the include search path.
 
Next, import the pygame.Surface module. In the init function add:

import_pygame_surface(); if (PyErr_Occurred ()) { /* do whatever you do when an error has occurred. */ }

If the module loads without an error then PySurface_New should be available. Its signature is:

PyObject PySurface_New(
SDL_Surface * info);

The factory function will return a new Pygame surface instance on success, with its surf field pointing to info. The new object takes responsiblity for releasing the surface. For an error, a Python exception is raised and NULL returned.

For examples using the Pygame api just look at the Pygame C source itself in the src subdirectory. Most of the modules import other Pygame modules. Files surface.c and mixer.c are particularly rich examples.

Hope this helps,

Lenard Lindstrom
On Sep 20, 2011, Scribble Master <scribbler95@xxxxxxxxx> wrote:
Thank you both for the advice! I think that PySurface_New would work for me.
This may seem a bit stupid, but where can I get the pygame API for C?