[PyOpenGL-Users] Bug? Importing WGL crashes glReadPixel call with "wrong argument type" exception
Brought to you by:
mcfletch
|
From: Anton O. <ant...@gm...> - 2017-09-02 19:31:36
|
Hello.
I am trying to use PyOpengGL for off-screen rendering, so I need WGL to
create gl context and then glReadPixels to retrieve data
First I wrote simple app with GLUT, but right after I import OpenGL.WGL
(just import, no more), the glReadPixels starts to crash with
ctypes.ArgumentError: argument 7: <type 'exceptions.TypeError'>: wrong type
The app, OpenGL version and stack trace are below. Now some of my
investigations
=======================================================
The crash starts in \OpenGL\GL\images.py line 369
GL_1_1.glReadPixels(
x,y,width,height,
format,type,
imageData
)
imageData in both cases is completely the same
The only difference in further workflow happens in
\OpenGL\platform\baseplatform.py line 125
def finalArgType( self, typ ):
"""Retrieve a final type for arg-type"""
if typ == ctypes.POINTER( None ) and not getattr( typ, 'final',False):
from OpenGL.arrays import ArrayDatatype
return ArrayDatatype
else:
return typ
With no WGL the 7th argument (while typ is <class 'ctypes.c_void_p'>) have
no "final" attribute set, so final type becomes ArrayDatatype and
everything works fine
But if to import WGL "final" flag is set, so <class 'ctypes.c_void_p'>
returned leading to "wrong type" exception in GL_1_1.glReadPixels call
I searched for "final" in WGL and found the following in
\OpenGL\raw\WGL\_types.py line 72
HANDLE = POINTER(None) # /home/mcfletch/pylive/OpenGL-ctypes/src/wgl.h:60
# TODO: figure out how to make the handle not appear as a void_p within the
code...
HANDLE.final = True
So we found who set up "final" flag for <class 'ctypes.c_void_p'>
But then I stuck up completely, have no single idea how to solve this type
conflict, suppose it's some issue in design
Have any idea how to solve it?
=======================================================
PyOpenGL package is
http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopengl
PyOpenGL‑3.1.1‑cp27‑cp27m‑win_amd64.whl
OpenGL.__version__
3.1.1
=======================================================
=======================================================
The App
=======================================================
# -*- coding: utf-8 -*-
# Just uncomment following line to reproduce the bug!
#import OpenGL.WGL
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
from PIL import Image
import sys
width, height = 300, 300
def init():
glClearColor(0.5, 0.5, 0.5, 1.0)
glColor(0.0, 1.0, 0.0)
gluOrtho2D(-1.0, 1.0, -1.0, 1.0)
glViewport(0, 0, width, height)
def render():
glClear(GL_COLOR_BUFFER_BIT)
glBegin(GL_LINES)
glVertex2d(-0.5, -0.5)
glVertex2d(0.5, 0.5)
glEnd()
glFlush()
def draw():
render()
glutSwapBuffers()
def main():
glutInit(sys.argv)
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
glutInitWindowSize(300, 300)
glutCreateWindow(b"OpenGL vs WGL")
init()
render()
glPixelStorei(GL_PACK_ALIGNMENT, 1)
data = glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE)
image = Image.frombytes("RGBA", (width, height), data)
image.save('output.png', 'PNG')
glutDisplayFunc(draw)
glutMainLoop()
main()
=======================================================
=======================================================
Stack trace with import WGL uncommented
=======================================================
Traceback (most recent call last):
File "C:/Users/Anton/Documents/Dev/PycharmProjects/OpenGL/OpenGLTest.py",
line 54, in <module>
main()
File "C:/Users/Anton/Documents/Dev/PycharmProjects/OpenGL/OpenGLTest.py",
line 47, in main
data = glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE)
File "C:\ProgramData\Anaconda2\lib\site-packages\OpenGL\GL\images.py",
line 372, in glReadPixels
imageData
File
"C:\ProgramData\Anaconda2\lib\site-packages\OpenGL\platform\baseplatform.py",
line 402, in __call__
return self( *args, **named )
ctypes.ArgumentError: argument 7: <type 'exceptions.TypeError'>: wrong type
|