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

[pygame] two questions and answers



i answered a pair of questions off the list, but the answers
are probably good information for everyone, i'm just forwarding
my own reply to the list here. the questions come courtesy of
Dirk K



> 1. Can you comment the problems you experience with incorporating OpenGL?

the problem was, i initialized the SDL display mode with the OpenGL flag,
but none of the pyopengl calls actually did any drawing. i'm not sure 
where the breakdown is happening, but i assume this should work as is.

if you want to test this for yourself, there's a pair of 'hidden'
functions in the display module. the functions pygame.display.testgl1()
will set the opengl surface attributes to reasonable 16bit values.
(that is single buffered too, and make sure to call it before 
display.set_mode(size, 16, OPENGL))
you can call pygame.display.testgl2() to simply fetch these values
and print them out.

if you're compiling your own pygame, it should be easy for you
to change these functions and try to get something working. i'd
really like this to work, so if you have a chance... try!



> 2. Will it be possible to access SDL instances from C AND from Python?

yes, pygame comes with a pretty complete C api. if you look in the
pygame.h you'll see some crude help and info. (don't be alarmed at
the code in that file, i followed the python instructions on how to
create a fully portable c library. an advantage is you don't need
to link to the pygame libraries when compiling. python takes care of
the linking for us)

anyways, the C api is mainly a set of converters between python 
objects and SDL objects. for example...
    PyObject* some_py_object = xxxx();
    if(PySurface_Check(some_py_object)) /*see if it is a surf*/
    {
        SDL_Surface* surf = PySurface_AsSurface(some_py_object);
        Uint32 color = SDL_MapRGB(surf, 50, 60, 120);
        SDL_Rect area = {10, 20, 100, 200};
        SDL_FillRect(surf, &area, color);
    }

it is pretty straightforward, and if you've done any C programming
for python, you'll find it follows all the same naming standards.

you can actually look at the source for pygame and see plenty of
examples on how to write your own code. the code used in pygame
works the same as if you were writing your own C functions with
pygame.

i've currently got an example of a python/c mixed application,
but i'm having a difficult time finding a way to get a nice
cross-platform compile for it. the best thing to do looks like
to write the function in both C and python, that way if your
python code can't find the compiled version it can fallback on
the python version it has. 

we'll definitely be seeing some more activity in this area.
but at this point it does work pretty well. the C api in pygame
is also open to suggestions, currently it just does what it
needs to get the job done, but it was designed to be used outside
of pygame as well.


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