我对 pyopengl 及其导入有一个奇怪的问题,下面是一个从一个更大的测试程序中剪下来的小测试程序,但这足以说明问题。您需要安装 PyOpenGL,如果您按原样运行它,它会显示一个空白窗口,如果您单击并拖动它会打印出一些 0。如果您取消注释下面的行HANDLE.final = True
,则它会停止工作,请参阅下面的回溯。
from OpenGL.GL import *
from OpenGL.GLUT import *
from ctypes import POINTER
import sys
HANDLE = POINTER(None)
#HANDLE.final = True
def display():
glutSwapBuffers()
glutInit(sys.argv)
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
glutInitWindowSize(400,400)
glutCreateWindow("GLUT Window")
glutDisplayFunc(display)
def readPx(x,y):
data_all = glReadPixels(x, y, 1, 1, GL_RGB, GL_BYTE)
print data_all
glutMotionFunc(readPx)
glutMainLoop()
未注释该行时,它会执行以下操作:
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\OpenGL\GLUT\special.py", line 130, in safeCall
return function( *args, **named )
File "C:\Users\Robin\dev\ogl_bug\ogl_bug.py", line 19, in readPx
data_all = glReadPixels(x, y, 1, 1, GL_RGB, GL_BYTE)
File "C:\Python27\lib\site-packages\OpenGL\GL\images.py", line 371, in glReadPixels
imageData
File "C:\Python27\lib\site-packages\OpenGL\platform\baseplatform.py", line 402, in __call__
return self( *args, **named )
ArgumentError: argument 7: <type 'exceptions.TypeError'>: wrong type
GLUT Motion callback <function readPx at 0x02CC5830> with (238, 190),{} failed: returning None argument 7: <type 'exceptions.TypeError'>: wrong type
在我更大的程序中,当尝试导入 OpenGL.raw.WGL._types(由任何 WGL Opengl 扩展导入但这是仍然导致错误的最小片段时)时,此 HANDLE 代码被深埋 5 或 6 个导入。
我不明白为什么这条线的存在会对看似不相关的 gl 调用产生影响——如何在不破坏 PyOpenGL 其他部分的情况下使用加载这个扩展?