[PyOpenGL-Users] funny return format of glGetTexImage
Brought to you by:
mcfletch
From: Patrick D. <pyo...@pd...> - 2013-10-28 14:08:43
|
Hi all, using glGetTexImageI have noticed two bugs: 1. according to the documentation the return value should always be an array if OpenGL.UNSIGNED_BYTE_IMAGES_AS_STRING == False which is not the case: OpenGL.UNSIGNED_BYTE_IMAGES_AS_STRING seems to be ignored completely and with type=GL_UNSIGNED_BYTE and the default for outputType a string is returned. Setting outputType=None returns an array. 2. image = glGetTexImage( GL_TEXTURE_RECTANGLE, level=0, format=GL_RGBA, format, type=GL_UNSIGNED_BYTE, outputType=None ) print "\timage:", type(image), image.shape, image.dtype prints image: <type 'numpy.ndarray'> (472L, 575L, 1L, 4L) uint8 (for format=GL_RGB the shape is (472L, 575L, 1L, 3L) ) In addition to the unused dimension 2 of the array, width and height are mixed up. My workaround is: image.shape = (image.shape[1], image.shape[0], image.shape[3]) which creates an image that looks fine apart from being mirrored along the horizontal axis. So to save it to disk, I do: im = PIL.Image.fromarray(image_data) im = im.transpose(PIL.Image.FLIP_TOP_BOTTOM) im.save('test.png', format="PNG") Regards, Patrick |