Thread: [PyOpenGL-Users] VBOs and gl*Pointer offset parameter
Brought to you by:
mcfletch
From: renaud b. <rnd...@gm...> - 2009-07-16 08:09:12
|
hello, i start to experiment with VBOs to prepare some code to the future of opengl :) i try to use a single array buffer to store a bunch of vertices and then the associated colors. as far as i understand, i should then use the last parameter of the usual gl[Vertex|Color]Pointer to pass the offset of the first element inside the array. for the vertices, it's 0, so i can pass None (the c functions expect a void* parameter). the problem is for non-zero offsets, e.g. for the colors in this case. it seems that the python wrapper interprets the last parameter as an array, and i have not found a way to pass an offset without "dewrapping" the function, i.e. offset = 12 glColorPointer.wrappedOperation(3, GL_FLOAT, 0, offset) # works glColorPointer(3, GL_FLOAT, 0, any_thing_i_could_think_of(offset)) # doesn't work i've tried several any_thing_i_could_think_of functions (casting to c_void_p, etc.) with no luck. any advice ? i've started looking into pyopengl code to see if the wrapper could be made more "clever" by distinguishing array-like and offset-like use of the last parameter but i need some time to fully understand the wrapping of the pointer functions. thanks for any advice, renaud |
From: Mike C. F. <mcf...@vr...> - 2009-07-16 18:50:12
|
renaud blanch wrote: > hello, > > i start to experiment with VBOs to prepare some code to the future of opengl :) > i try to use a single array buffer to store a bunch of vertices and > then the associated colors. > as far as i understand, i should then use the last parameter of the > usual gl[Vertex|Color]Pointer to pass the offset of the first element > inside the array. > for the vertices, it's 0, so i can pass None (the c functions expect a > void* parameter). > the problem is for non-zero offsets, e.g. for the colors in this case. > it seems that the python wrapper interprets the last parameter as an > array, and i have not found a way to pass an offset without > "dewrapping" the function, i.e. > > offset = 12 > glColorPointer.wrappedOperation(3, GL_FLOAT, 0, offset) # works > glColorPointer(3, GL_FLOAT, 0, any_thing_i_could_think_of(offset)) # > doesn't work > > i've tried several any_thing_i_could_think_of functions (casting to > c_void_p, etc.) with no luck. > any advice ? > I'm afraid I'm so accustomed to using the OpenGL.arrays.vbo.VBO wrapper that I haven't documented the base operation: ctypes.c_void_p( 12 ) should work as an array offset of 12 bytes, if it isn't, let me know and I'll dig into why it's not working for you (failing code would be helpful). The wrapper includes a VBOOffset type which basically is interpreted as an offset when using the wrapper (they're created with myVBO + byteOffset). HTH, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com |
From: Mike C. F. <mcf...@vr...> - 2009-07-17 18:34:21
|
renaud blanch wrote: > On Thu, Jul 16, 2009 at 8:32 PM, Mike C. Fletcher<mcf...@vr...> wrote: > ... >> ctypes.c_void_p( 12 ) >> >> should work as an array offset of 12 bytes, ... > no, it does not work (at least for me). > that's what i was also doing. > Argh. ctypes c_void_p is a parameter type, not a pointer type (I knew this, but I mis-coded for it). I've checked a 2-line patch into the OpenGL.arrays.ctypesparameters file, it should show up in the next release (which should happen reasonably soon, if I ever get enough time to test). In the meantime, the following patch should work, or you could use bzr head of PyOpenGL. HTH, Mike === modified file 'OpenGL/arrays/ctypesparameters.py' --- OpenGL/arrays/ctypesparameters.py 2009-04-09 19:06:55 +0000 +++ OpenGL/arrays/ctypesparameters.py 2009-07-17 18:21:38 +0000 @@ -30,7 +30,7 @@ return ctypes.byref( value ) from_param = voidDataPointer = classmethod( from_param ) def dataPointer( cls, value ): - if isinstance( value, ParamaterType ): + if isinstance( value, DIRECT_RETURN_TYPES ): return value else: return ctypes.addressof( value ) @@ -95,6 +95,8 @@ yield length def asArray( self, value, typeCode=None ): """Convert given value to an array value of given typeCode""" + if isinstance( value, DIRECT_RETURN_TYPES ): + return value if isinstance( value, ParamaterType ): value = value._obj return ctypes.byref( value ) -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com |
From: Mike C. F. <mcf...@vr...> - 2009-07-24 22:32:55
|
renaud blanch wrote: > On Fri, Jul 17, 2009 at 8:34 PM, Mike C. Fletcher<mcf...@vr...> wrote: > ... > thanks, the patch didn't work against my installed version of > pyopengl, but 3.0.1a1 did it. > > the only thing is that i had to change the order of platform plugin > declarations so that 'darwin' comes before 'posix'. > on the mac os.name is 'posix', and thus the GLX platform was found > first and failed to load. > I've changed the plugin to prefer sys.platform over os.name when doing resolution. That should mean that on Linux it is the linux2 plugin preferred. I'm presuming that os-x has sys.platform == 'darwin', so the fix should work there too. Thanks for the error report(s), Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com |