win7 32位 python3.6
正常是pip install pyopengl 编译样例文件后提示错误:
OpenGL.error.NullFunctionError: Attempt to call an undefined function glutInit, check for bool(glutInit) before calling
原因是:32位系统缺少freeglut32.vc14.dll,这个文件必须指定在site-packages\OpenGL/DLLS这个文件夹。
https://pypi.org/project/PyOpenGL/#files
在这个网站里下载原文件PyOpenGL-3.1.6.tar.gz,里面的DLLS文件夹里有对应的各个版本的freeglut.dll
运行网上下载的样例,有一个bug,就是窗口标题名必须是个字节串。
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
def drawFunc():
glClear(GL_COLOR_BUFFER_BIT)
#glRotatef(1, 0, 1, 0)
glutWireTeapot(0.5)
glFlush()
glutInit(sys.argv)
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA)
glutInitWindowSize(400, 400)
glutCreateWindow(b"DD")#如果不用字节串,就会提示类型错误。
glutDisplayFunc(drawFunc)
#glutIdleFunc(drawFunc)
glutMainLoop()