Thread: [PyOpenGL-Users] [SOLVED] glDrawArrays and PyOpenGL 3.0.0a6 anything changed?
Brought to you by:
mcfletch
From: V. A. S. <so...@es...> - 2007-10-05 07:40:58
|
Hello again, PROBLEM The following code was working fine on PyOpenGL 2.0.1.09: GL.glVertexPointerf(self.vertices) GL.glColorPointerf(self.vertexColors) GL.glEnableClientState(GL.GL_VERTEX_ARRAY) GL.glEnableClientState(GL.GL_COLOR_ARRAY) GL.glDrawArrays(GL.GL_POINTS, 0, xsize*ysize) but now it does not work under PyOpenGL 3.0.0.a6: WindowsError: exception: access violation reading 0x0BD20028 If instead of using glDrawArrays, I loop for all the vertices and colors, the program works (of course very slowly): GL.glBegin(GL.GL_POINTS) for i in range(xsize * ysize): GL.glColor4fv(self.vertexColors[i]) GL.glVertex(self.vertices[i]) GL.glEnd() SOLUTION I set a white color with glColor3ub(255, 255, 255) and removed the glEnableClientState(GL_COLOR_ARRAY) and I got my image plotted. I checked the type of my arrays and found out they were float64 (and not float32). It seems glVertexPointerf and glColor4fv convert doubles to floats and nothing happens but glColorPointerf is unable to do it. Just changing glColorPointerf(self.vertexColors) by glColorPointerd(self.vertexColors) solved my problem. I prefer to have the things forced and to avoid automatic transformations, but I would have preferred a clearer error message :-) Thanks for your time, Armando |
From: Mike C. F. <mcf...@vr...> - 2007-10-08 17:10:34
|
V. Armando Sole wrote: ... > The following code was working fine on PyOpenGL 2.0.1.09: > > GL.glVertexPointerf(self.vertices) > GL.glColorPointerf(self.vertexColors) > GL.glEnableClientState(GL.GL_VERTEX_ARRAY) > GL.glEnableClientState(GL.GL_COLOR_ARRAY) > GL.glDrawArrays(GL.GL_POINTS, 0, xsize*ysize) > ... > Just changing glColorPointerf(self.vertexColors) by > glColorPointerd(self.vertexColors) solved my problem. > Okay, that's weird. I've just written a test like so (against current CVS): def test_numpyConversion( self ): """Test that we can run a numpy conversion from double to float for glColorArray""" import numpy a = numpy.arange( 0,1.2, .1, 'd' ).reshape( (-1,3 )) glEnableClientState(GL_VERTEX_ARRAY) glColorPointerf( a ) glColorPointerd( a ) and it produced no errors. Can you produce a minimal test that shows the error occurring? The system *should* be able to convert from double to float (as shown with this test). Could be that it's some bug I don't recall fixing, but that doesn't seem likely. Good luck, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com |
From: <so...@es...> - 2007-10-08 21:18:06
Attachments:
OpenGLTest.py
|
Hello, Quoting "Mike C. Fletcher" <mcf...@vr...>: > ... Can you produce a minimal test that shows > the error occurring? The system *should* be able to convert from double > to float (as shown with this test). Could be that it's some bug I don't > recall fixing, but that doesn't seem likely. > I send you a file showing the problem. python OpenGLTest.py 0 uses float32 python OpenGLTest.py 1 uses float64 and crashes python OpenGLTest.py 2 uses float64 and glColorPointerd and does not crash. My platform is windows XP. The problem is present on Python 2.4 and Python 2.5 BTW, glReadPixelsub(x, y, 1, 1, GL_RGBA) returns 'int8' instead of 'uint8' and I am forced to implement things like: color = GL.glReadPixelsub(x, y, 1, 1, GL.GL_RGBA) #workaround a PyOpenGL bug? if color.dtype == 'int8': color = color.astype(numpy.uint8) Best regards, Armando ------------------------------------------------- This mail sent through IMP: http://horde.org/imp/ |
From: Mike C. F. <mcf...@vr...> - 2007-10-09 02:36:10
|
so...@es... wrote: > Hello, > > Quoting "Mike C. Fletcher" <mcf...@vr...>: > > >> ... Can you produce a minimal test that shows >> the error occurring? The system *should* be able to convert from double >> to float (as shown with this test). Could be that it's some bug I don't >> recall fixing, but that doesn't seem likely. >> >> > > I send you a file showing the problem. > > python OpenGLTest.py 0 uses float32 > python OpenGLTest.py 1 uses float64 and crashes > python OpenGLTest.py 2 uses float64 and glColorPointerd and does not crash. > > My platform is windows XP. The problem is present on Python 2.4 and Python 2.5 > The problem was actually in the caching of the temporary array. Under the covers, PyOpenGL has to retain a copy of the copied array in order to prevent it going out of scope and causing crashes. There was a bug in the code that stores the copy, so that it was recording based on the array data-type (e.g. float) rather than the array role (e.g. vertex array). So if you used two arrays that both had to be converted and both were of the same final type, you'd overwrite the one array with the next and wind up with a crash when you tried to access the data in the first array. This patch seems to fix the issue: Index: OpenGL/GL/pointers.py =================================================================== RCS file: /cvsroot/pyopengl/OpenGL-ctypes/OpenGL/GL/pointers.py,v retrieving revision 1.22 diff -C3 -r1.22 pointers.py *** OpenGL/GL/pointers.py 8 Feb 2007 02:24:40 -0000 1.22 --- OpenGL/GL/pointers.py 9 Oct 2007 02:13:50 -0000 *************** *** 105,120 **** function= wrapper.wrapper( baseFunction ) assert not getattr( function, 'pyConverters', None ), """Reusing wrappers?""" if arrayType: ! arrayType = arrays.GL_CONSTANT_TO_ARRAY_TYPE[ glType ] ! function.setPyConverter( 'pointer', arrays.asArrayType(arrayType) ) ! function.setCResolver( 'pointer', arrayType.voidDataPointer ) else: function.setPyConverter( 'pointer', arrays.AsArrayOfType('pointer','type') ) function.setCResolver( 'pointer', arrays.ArrayDatatype.voidDataPointer ) function.setCConverter( 'pointer', converters.getPyArgsName( 'pointer' ) ) if 'size' in function.argNames: function.setPyConverter( 'size' ) ! function.setCConverter( 'size', arrays.arraySizeOfFirstType(arrayType,defaultSize) ) if 'type' in function.argNames: function.setPyConverter( 'type' ) function.setCConverter( 'type', glType ) --- 105,120 ---- function= wrapper.wrapper( baseFunction ) assert not getattr( function, 'pyConverters', None ), """Reusing wrappers?""" if arrayType: ! arrayModuleType = arrays.GL_CONSTANT_TO_ARRAY_TYPE[ glType ] ! function.setPyConverter( 'pointer', arrays.asArrayType(arrayModuleType) ) ! function.setCResolver( 'pointer', arrayModuleType.voidDataPointer ) else: function.setPyConverter( 'pointer', arrays.AsArrayOfType('pointer','type') ) function.setCResolver( 'pointer', arrays.ArrayDatatype.voidDataPointer ) function.setCConverter( 'pointer', converters.getPyArgsName( 'pointer' ) ) if 'size' in function.argNames: function.setPyConverter( 'size' ) ! function.setCConverter( 'size', arrays.arraySizeOfFirstType(arrayModuleType,defaultSize) ) if 'type' in function.argNames: function.setPyConverter( 'type' ) function.setCConverter( 'type', glType ) > BTW, glReadPixelsub(x, y, 1, 1, GL_RGBA) returns 'int8' instead of 'uint8' and I > am forced to implement things like: > > color = GL.glReadPixelsub(x, y, 1, 1, GL.GL_RGBA) > #workaround a PyOpenGL bug? > if color.dtype == 'int8': > color = color.astype(numpy.uint8) I'm using glReadPixelsub in the readpixelleak test in OpenGLContext and the result is coming back as a uint8 array there. Sorry to be a pain, but have you got a bit of code where I could see the failure (it's pretty easy to fire up pdb and trace through the wrappers to see where something goes wrong with the 3.x version)? HTH, and thanks for the bug report, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com |
From: V. A. S. <so...@es...> - 2007-10-09 06:43:30
Attachments:
OpenGLTest.py
|
Hello, Thank you for your continued PyOpenGL development and support. It is really great. At 22:36 08/10/2007 -0400, Mike C. Fletcher wrote: >I'm using glReadPixelsub in the readpixelleak test in OpenGLContext and >the result is coming back as a uint8 array there. Sorry to be a pain, but >have you got a bit of code where I could see the failure Just adding the code below to the previously submitted file illustrates the problem. I send the file as attachment but it is just to avoid problems because it is the same file as before. (Just click on the displayed widget) def mousePressEvent(self, event): self.lastPos = qt.QPoint(event.pos()) #get the color x = self.lastPos.x() y = self.lastPos.y() y = self.height()- y self.makeCurrent() color = GL.glReadPixelsub(x, y, 1, 1, GL.GL_RGBA) #workaround a PyOpenGL bug if color.dtype == 'int8': print "WARNING: int8 received" color = color.astype(numpy.uint8) else: print "received %s" % color.dtype print "Color = ", color (Well, actually is not needed to use that PyQt specific approach, just adding the lines below to the end of the paintGL method is enough): color = GL.glReadPixelsub(0, 0, 1, 1, GL.GL_RGBA) if color.dtype == 'int8': print "WARNING: int8 received" >(it's pretty easy to fire up pdb and trace through the wrappers to see >where something goes wrong with the 3.x version) After all your effort to convert PyOpenGL to ctypes I guess I will have to learn to use pdb ... :) Best regards, Armando |
From: Mike C. F. <mcf...@vr...> - 2007-10-09 12:44:26
|
V. Armando Sole wrote: ... > Just adding the code below to the previously submitted file > illustrates the problem. I send the file as attachment but it is just > to avoid problems because it is the same file as before. (Just click > on the displayed widget) With the latest CVS version, on clicking I get: mcfletch@raistlin:~/OpenGL-dev/OpenGL-ctypes/OpenGL/tests$ python glreadpixelsubformat.py 1 received uint8 Color = [[[128 128 128 255]]] ... > if color.dtype == 'int8': > print "WARNING: int8 received" > color = color.astype(numpy.uint8) > else: > print "received %s" % color.dtype > print "Color = ", color which suggests that the problem has been fixed between the last release and now. I'm planning to do a beta-1 release this week, incidentally. Good luck, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com |