【问题标题】:PyOpenGL on MacOS BigSur and OpenGL.error.NullFunctionError [duplicate]MacOS BigSur 和 OpenGL.error.NullFunctionError 上的 PyOpenGL [重复]
【发布时间】:2021-03-19 23:30:22
【问题描述】:

我什至无法运行使用 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。我已使用this 教程修改了 PyOpenGL 文件以修复其他错误。

【问题讨论】:

    标签: python macos opengl glut pyopengl


    【解决方案1】:

    这个问题的原因和你提到的question很相似。

    要解决这个问题,只需替换该行(在文件 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'
    

    【讨论】:

      猜你喜欢
      • 2021-03-04
      • 1970-01-01
      • 2019-03-25
      • 2021-07-05
      • 2021-03-19
      • 2021-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多