On 14 Jan., 11:58, "Alex Holkner" <[EMAIL PROTECTED]> wrote: > On Jan 14, 2008 9:53 PM, jimknopf <[EMAIL PROTECTED]> wrote: > > > > > > > Hi, > > > I am currently playing with PyGlet in combination with Box2d (physics > > engine). I want to parse SVG like pathes (polygons) for both, Box2D > > and game graphics. My problem is, that Box2D only accepts convex > > polygons, which is why I need some kind of simple polygon > > decomposition / triangulation algorithm. > > > As far as I have undestood, GLU offers triangulation using the > > tesselator module. And PyGlet offers GLU bindings. > > > What I tryed: > > > points = ([0.0,0.0,0.0],[10.0,0.0,0.0],[0.0,10.0,0.0],) > > tess = gluNewTess() > > gluTessBeginPolygon(tess, None) > > gluTessBeginContour(tess) > > for point in points: > > gluTessVertex(tess, point, point) > > gluTessEndContour() > > gluTessEndPolygon() > > > What Python thinks about my code: > > > "[...] > > Traceback (most recent call last): > > File "Bezier.py", line 123, in <module> > > space.main_loop() > > File "Bezier.py", line 101, in main_loop > > gluTessVertex(tess, point, point) > > ctypes.ArgumentError: argument 2: <type 'exceptions.TypeError'>: > > expected LP_c_double instance instead of list" > > > To be honest, I have not worked with OpenGL before, which is why I do > > not know, whether this is a PyGlet problem or something else (maybe I > > simply misundestood the whole Tesselator thingy). But it sounds like a > > problem with the GLU bindings. > > You'll need to construct ctypes arrays to pass to these functions. > See the ctypes documentation for a good tutorial. For now, this > should get you started: > > import ctypes > points = ([0.0,0.0,0.0],[10.0,0.0,0.0],[0.0,10.0,0.0],) > points = [(ctypes.c_double * len(v))(*v) for v in points] > > Alex.
Thanks, worked for me, but am I really supposed to get in contact with the ctypes module? All tutorials/snippets I found seem to base on the OpenGL.GLU bindings, which take care of stuff like this. So I assume, using pyglet.gl.glu as complete beginner (concerning GLU) is not the best option? Because my next problem is, that gluTessCallback() expects a CFunctionType instance instead of a python function. And after reading the "Callback Function" section in the ctypes tutorial I still do not know how to use a python instance method (self.combine or whatever) together with gluTessCallback(). Should I a) take some time to get into the ctypes module, or b) look for alternatives for polygon decomposition? - Michael --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pyglet-users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/pyglet-users?hl=en -~----------~----~----~----~------~----~------~--~---
