为了进入PyOpenGL,我将遵循这本非常简单的指南。
-
我安装了
pip install PyOpenGL PyOpenGL_accelerate
,一切都很好。 -
我通过测试代码测试了安装:
导入OpenGL。GL导入OpenGL。供过于求导入OpenGL。GLUprint("Imports successfully!"(#如果你看到这个打印到控制台,那么安装成功
所有良好
我现在运行这个脚本:
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
w,h= 500,500
def square():
glBegin(GL_QUADS)
glVertex2f(100, 100)
glVertex2f(200, 100)
glVertex2f(200, 200)
glVertex2f(100, 200)
glEnd()
def iterate():
glViewport(0, 0, 500, 500)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(0.0, 500, 0.0, 500, 0.0, 1.0)
glMatrixMode (GL_MODELVIEW)
glLoadIdentity()
def showScreen():
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
iterate()
glColor3f(1.0, 0.0, 3.0)
square()
glutSwapBuffers()
glutInit()
glutInitDisplayMode(GLUT_RGBA)
glutInitWindowSize(500, 500)
glutInitWindowPosition(0, 0)
wind = glutCreateWindow("OpenGL Coding Practice")
glutDisplayFunc(showScreen)
glutIdleFunc(showScreen)
glutMainLoop()
我收到的错误是OpenGL.error.NullFunctionError: Attempt to call an undefined function glutInit, check for bool(glutInit) before calling
所以我在网上读了一些指南,他们指向从这里下载轮子。所以我继续下载PyOpenGL_accelerate‑3.1.5‑cp38‑cp38‑win_amd64.whl
和PyOpenGL‑3.1.5‑cp38‑cp38‑win_amd64.whl
,因为我正在运行Python 3.8
pip install .PyOpenGL_accelerate-3.1.5-cp39-cp39-win_amd64.whl
返回PyOpenGL-accelerate is already installed with the same version as the provided wheel. Use --force-reinstall to force an installation of the wheel.
pip install .PyOpenGL_accelerate-3.1.5-cp38-cp38-win_amd64.whl
返回PyOpenGL-accelerate is already installed with the same version as the provided wheel. Use --force-reinstall to force an installation of the wheel.
一个如此简单的指南怎么会让我得到如此痛苦的结果?
如何检查是否安装了Visual C++ 14.0 build tools
。也许这是我唯一缺少的一步?
由于"用于Python扩展包的非官方Windows二进制文件";不再存在(请参阅Christoph Gohlke的Windows Wheels网站将于本月底关闭(,以下解决方案不再有效:
包中缺少_freeglut_DLL。Unistall";PyOpenGL":
pip uninstall pyopengl
从Unofficial Windows Binaries for Python Extension Packages下载软件包转轮(例如:"PyOpenGL‑3.1.6‑cp311‑cp311-win_amd64.whl"(并安装:
pip install PyOpenGL‑3.1.6‑cp311‑cp311‑win_amd64.whl
相反,您必须克隆mcfletch/pyopengl存储库并从存储库安装pyopengl(另请参阅pyopengl和pyopengl_Accelerate(:
克隆存储库:
git clone https://github.com/mcfletch/pyopengl
安装pyopengl和pyopengl_accelerate:
cd pyopengl
pip install -e .
cd accelerate
pip install -e .