本文介绍了MacOS BigSur上的PyOpenGL和OpenGL.error.NullFunctionError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
即使使用OpenGL/GLUT的最简单的程序,我也无法运行.
I can't run even the simplest program that is using 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()
我总是收到此错误消息:
I always receive this error message:
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文件修改为修复其他错误.
I'm using MacOS Big Sur 20B29, python 3.8.5 and PyOpenGL 3.1.5. I have modified the PyOpenGL file using this tutorial to fix other error.
推荐答案
此问题的原因与.
要解决此问题,只需替换该行(在OpenGL/platform/ctypesloader.py文件中)
To address this problem, just replace the line (in the file 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'
这篇关于MacOS BigSur上的PyOpenGL和OpenGL.error.NullFunctionError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!