Luiji Maryo skrev:
> As for project background, this has to do with an argument with
> colleges of mine.  We wanted to make a game, and I brought up the
> greatness of Python, but they said that it would be too slow for game
> development.  Even though it is sufficiently fast, the game we were
> working on was very graphics intensive and when comparing a C version
> to a Python version of basic design philosophy C was noticably faster.
>
>   
Several games use Python for game logics, including Battlefield 2 and 
Civilization IV. But you would obviously not write your graphics engine 
in Python (OpenCL might change that in the future).

There are good 3D engines callable from Python though, such as PyOgre 
and Disney's Panda3d (which they have used for several games, e.g. 
Pirates of the Caribbean).

You should also take a look at PyGame. It is a pythonic wrapper around 
SDL. It allows you to write cross-platform game and multimedia apps in 
Python. SDL/PyGame uses DirectX (sound, input, 2D) and OpenGL (3D) on 
Windows.

I am working on a small program that use OpenGL for visualizing large 
amounts of scientific data. I have written some of the code that calls 
OpenGL in C, and simply call that from Python. In my experience, if I 
have a loop that calls glVertex* many times, it makes sence to write 
that loop in C. Iterating in Python and making thousands of calls to 
glVertex* (using ctypes or PyOpenGL) obviously gives me slow graphics. 
But the complexity between writing these loops in C (or Cython) and 
Python is really minue, if any. It is all the other stuff that matters.

There are other tricks that work as well, and allows fast OpenGL 
graphics in Python without using C:

- Display lists. They are slower to make, but execute equally fast.
- Vertex arrays with NumPy arrays as buffer.
- Vertex buffers in video RAM.
- Python is fantastic for working with vertex shaders and OpenCL.

Vertex arrays usng NumPy (and to a lesser extent display lists) can be a 
drop-in replacement for multiple calls to glVertex*.

For graphics using vertex shaders and OpenCL, Python is actually better 
than C or C++. It might seems surprising, until you realize it is just 
text manipulation on your part.  We can manipulate text faster and  more 
easily in Python than C++. Thus, Python is a better choise for 
generating vertex shaders and OpenCL code, and the OpenGL/OpenCL driver 
does the rest.

In my experience, tight loops with calls to glVertex* is the only place 
where Python can be proven "too slow".

A graphics intensive program will need to store data contiguous buffers. 
I prefer NumPy, but you can also use the array module from Python's 
standard library (or tuples, but not lists).


Regards,
Sturla



_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to