Python and 3d

sturlamolden sturlamolden at yahoo.no
Thu Sep 17 15:21:11 CEST 2009


On 14 Sep, 00:05, Carl Banks <pavlovevide... at gmail.com> wrote:

> Dice3DS works fine with PyOpenGL 3.x.

PyOpenGL is a bad idea anyway, due to the overhead of Python function
calls and ctypes. Doing 3D in "pure" Python at least requires NumPy
arrays as vertex arrays and/or extensive use of display lists. But
there are better alternatives.

My current approach is use Cython + NumPy, and accumulate calls to
OpenGL in a C function. I prefer to keep calls to OpenGL in C (not
Cython), because this way I don't have to define the OpenGL API to
Cython. Cython merely becomes a glue layer between Python and C. With
NumPy support in Cython, this is a nice way of storing contiguous
vertex array. NumPy even allows Fortran ordering, which is used by
OpenGL.

Another nice way of using OpenGL from Python is the Fortran bindings
(f90gl or F03GL). One can accumulate calls to OpenGL in a Fortran 95
subroutine, and make it callable from Python with f2py.










More information about the Python-list mailing list