python - 如何在mac os中修复“尝试调用未定义的函数glutInit,在调用之前检查bool(glutInit)”
问题描述
当我尝试在 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 中解决它。
解决方案
推荐阅读
- java - 如何在我的 Spring Boot 应用程序中访问 Jar 文件的 Controller 类中提到的 Rest API
- reactjs - 使用 Reactjs + Electron 最简单的流认证(无需任何特殊服务)
- android - 如何在一夜之间停止android自动覆盖调试apk?
- php - 如何将带有变量的 where 条件添加到我的控制器?
- c# - 如何在 Visual Studio 的 C# 中创建服务引用?
- tensorflow - 在张量流中表示高精度浮点数
- mysql - 行从 MySQL 中消失,最大允许大小可能是原因吗?
- exception - Future.wait() 没有捕获异常 (Dart)
- typescript - 部分检查中的道具,但仍未定义?
- ruby - Github 操作,从秘密中设置 gem 用户名:请 CGI 转义您的用户名和密码,然后再设置它们以进行身份验证