2009/2/12 [email protected] <[email protected]>: > > Hi! > I cannot recognise what sort of python construct is this, > i do understand though that it's needed for passing arrays in opengl. > > vertices_gl = (GLfloat * len(vertices))(*vertices) > > This means multipling a type with an int and then calling it ? > Or casting ? > Never seen anything like this in python.
ctypes uses a trick whereby multiplying a base type by an int gives you a type representing an array of that length, e.g. >>> import ctypes >>> ctypes.c_float * 4 <class '__main__.c_float_Array_4'> This is obviously easier than having explicit types for every possible array length. Pyglet uses ctypes to interface with OpenGL, and thus a lot of ctypes idioms are used. In this case, (GLfloat * len(vertices) gives the class for float arrays of that length, and then the constructor is called with the contents of vertices as arguments, giving a ctypes array corresponding to the plain Python list. Martin --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
