On 10 Des, 13:33, Achim Domma <do...@procoder s.netwrote:
I'm looking for quite some time now for a gui library for python,
which allows me to display 3D graphics. Main OS is windows, Mac OS X
and Linux would be nice to have. I want to use python 2.5. My first
try was wx + pyOpenGL but there are no working binaries for python
2.5.
Huh? The latest version of PyOpenGL uses ctypes and has no binaries as
it is implemented in pure Python. Personally I use my own ctypes
wrapper for the few OpenGL routines I need. There is a lot of unwanted
overhead in PyOpenGL.
Also consider calling OpenGL from a Pyrex extension. That may save you
some overhead if you make a lot of calls to the OpenGL library. A
remedy for that may be to use display lists, or combine vertex arrays
or vertex buffers with NumPy arrays.
Excerpts from my OpenGL wrapper:
from ctypes import *
import numpy
from threading import Lock
opengl_lock = Lock()
GL = windll.opengl32
GLU = windll.glu32
GL_PROJECTION = 0x1701
GL_MODELVIEW = 0x1700
GL_DEPTH_TEST = 0x0B71
GL_VERTEX_ARRAY = 0x8074
GL_NORMAL_ARRAY = 0x8075
glBegin = GL.glBegin
glBegin.argtype s = (c_int,)
glBegin.restype = None
glEnd = GL.glEnd
glEnd.argtypes = ()
glEnd.restype = None
glVertex3f = GL.glVertex3f
glVertex3f.argt ypes = (c_float, c_float, c_float)
glVertex3f.rest ype = None
gltypemap = {
GL_BYTE : numpy.ctypeslib .ndpointer(dtyp e = numpy.int8,
flags='aligned, contiguous'),
GL_UNSIGNED_BYT E : numpy.ctypeslib .ndpointer(dtyp e = numpy.uint8,
flags='aligned, contiguous'),
GL_SHORT : numpy.ctypeslib .ndpointer(dtyp e = numpy.int16,
flags='aligned, contiguous'),
GL_UNSIGNED_SHO RT : numpy.ctypeslib .ndpointer(dtyp e =
numpy.uint16, flags='aligned, contiguous'),
GL_INT : numpy.ctypeslib .ndpointer(dtyp e = numpy.int32,
flags='aligned, contiguous'),
GL_UNSIGNED_INT : numpy.ctypeslib .ndpointer(dtyp e = numpy.uint32,
flags='aligned, contiguous'),
GL_FLOAT : numpy.ctypeslib .ndpointer(dtyp e = numpy.float32,
flags='aligned, contiguous'),
GL_DOUBLE : numpy.ctypeslib .ndpointer(dtyp e = numpy.float64,
flags='aligned, contiguous'),
GL_UNSIGNED_BYT E_3_3_2 : numpy.ctypeslib .ndpointer(dtyp e =
numpy.uint8, flags='aligned, contiguous')
}
def glVertexPointer (size, gltype, stride, array):
opengl_lock.acq uire()
glfun = GL.glVertexPoin ter
glfun.argtypes = (c_int, c_int, c_int, gltypemap[gltype])
glfun.restype = None
glfun(size, gltype, stride, array)
opengl_lock.rel ease()
def glGenBuffersARB (n):
opengl_lock.acq uire()
PFNGLGENBUFFERS ARBPROC = WINFUNCTYPE(Non e, c_uint,
gltypemap[GL_UNSIGNED_INT])
wglGetProcAddre ss = GL.wglGetProcAd dress
wglGetProcAddre ss.argtypes = (c_char_p,)
wglGetProcAddre ss.restype = PFNGLGENBUFFERS ARBPROC
glfun = wglGetProcAddre ss('glGenBuffer sARB')
buffers = numpy.zeros(n, dtype=numpy.uin t32)
glfun(n, buffers)
opengl_lock.rel ease()
return buffers
Interfacing Python with OpenGL is not rocket science.