python 安装OpenGl 环境

pip install pyopengl

若出错:

https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopengl 下载与python对应的版本

PyOpenGL-3.1.2-cp37-cp37m-win32.whl

确保python和opengl版本一致

安装好后测试代码:

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()
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA)
glutInitWindowSize(400, 400)
#参数为b类型而不是string
glutCreateWindow(b"First")
glutDisplayFunc(drawFunc)
#glutIdleFunc(drawFunc)
glutMainLoop()

Leave a Reply