如何修复mac os中的“尝试调用未定义函数glutInit,在调用前检查bool(glutInit)”

2024-09-29 17:12:53 发布

您现在位置:Python中文网/ 问答频道 /正文

当我尝试在Mac中使用pyopengl时,发生了此错误。我找到了使用windows的解决方案。但我不知道如何在Mac中修复它

这是我的代码:

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

import os

def initFunc():
    glDisable(GL_DEPTH_TEST)
    glClearColor(0.0, 0.0, 0.0, 0.0)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    gluOrtho2D(0.0, 400.0, 0.0, 400.0)

def displayFunc():
    glClear(GL_COLOR_BUFFER_BIT)
    glColor3f(1.0, 1.0, 1.0)
    glBegin(GL_TRIANGLES)
    glVertex2f(10.0, 10.0)
    glVertex2f(10.0, 100.0)
    glVertex2f(100.0, 100.0)
    glEnd()
    glFlush()

if __name__ == '__main__':
    glutInit()
    glutInitWindowSize(400,400)
    glutCreateWindow("GL test")
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
    glutDisplayFunc(displayFunc)
    initFunc()
    os.system('''/usr/bin/osascript -e 'tell app "Finder" to set frontmost of process 
    "Python" to true' ''')
    # prevent GL window from appearing behind other applications
    glutMainLoop()

这就是错误所在

    Traceback (most recent call last):
      File "/Users/wupeihan/Project/learning/python/opengl/traingle.py", line 25, in <module>
        glutInit()
      File "/Users/wupeihan/miniconda3/envs/opengl/lib/python3.7/site- 
    packages/OpenGL/GLUT/special.py", line 333, in glutInit
        _base_glutInit( ctypes.byref(count), holder )
      File "/Users/wupeihan/miniconda3/envs/opengl/lib/python3.7/site- 
    packages/OpenGL/platform/baseplatform.py", line 425, in __call__
        self.__name__, self.__name__,
    OpenGL.error.NullFunctionError: Attempt to call an undefined function glutInit, check for 
    bool(glutInit) before calling

我想知道如何在Mac中解决它


Tags: tonamefromimportmaccallusersfile

热门问题