PyOpenGL on MacOS BigSur and OpenGL.error.NullFunctionError



即使是使用OpenGL/GLUT的最简单的程序,我也无法运行。

from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *

def showScreen():
# Remove everything from screen (i.e. displays all white)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

glutInit()  # Initialize a glut instance which will allow us to customize our window
glutInitDisplayMode(GLUT_RGBA)  # Set the display mode to be colored
glutInitWindowSize(500, 500)   # Set the width and height of your window
# Set the position at which this windows should appear
glutInitWindowPosition(0, 0)
wind = glutCreateWindow("OpenGL Coding Practice")  # Give your window a title
# Tell OpenGL to call the showScreen method continuously
glutDisplayFunc(showScreen)
# Draw any graphics or shapes in the showScreen function at all times
glutIdleFunc(showScreen)
glutMainLoop()

我总是收到这样的错误消息:

Traceback (most recent call last):
File "/Users/xyz/jebacglut123.py", line 11, in <module>
glutInit()  # Initialize a glut instance which will allow us to customize our window
File "/usr/local/anaconda3/envs/opengl/lib/python3.8/site-packages/OpenGL/GLUT/special.py", line 362, in glutInit
_base_glutInit(ctypes.byref(count), holder)
File "/usr/local/anaconda3/envs/opengl/lib/python3.8/site-packages/OpenGL/platform/baseplatform.py", line 423, in __call__
raise error.NullFunctionError(
OpenGL.error.NullFunctionError: Attempt to call an undefined function glutInit, check for bool(glutInit) before calling

我使用的是MacOS Big Sur 20B29、python 3.8.5和PyOpenGL 3.1.5。我使用本教程修改了PyOpenGL文件以修复其他错误。

这个问题的原因与您提到的问题中的原因非常相似。

要解决这个问题,只需替换(OpenGL/platform/ctypesloader.py文件中的(行

fullName = util.find_library( name )

带有

if name == 'OpenGL':
fullName = '/System/Library/Frameworks/OpenGL.framework/OpenGL'
elif name == 'GLUT':
fullName = '/System/Library/Frameworks/GLUT.framework/GLUT'

最新更新