1.建议去官网下载安装包安装Python,一般会自动安装pip的。环境变量配置如果你没在安装时勾选,就自己配置吧。
2.win + r 输入cmd 进入命令行,输入pip install pyopengl 会自动安装pyopengl包的。
3.从网上测试运行环境下载了个代码
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()
直接运行。
4.如果报错。报错内容包含
OpenGL.error.NullFunctionError: Attempt to call an undefined function glutInit, check for bool(glutInit) before calling
请下载http://pan.baidu.com/s/1hrp2J7Q文件解压后,如果是32位系统复制到C:\Windows\System32目录下,如果是
64位系统复制到C:\Windows\SysWOW64目录下。如果提示有同名文件,最好选择跳过而不要替换。
5.注意glutCreateWindow()函数,网上我搜的代码是传递的参数是string类型,可惜我运行报错了,然后再google后,改成了上例代码b类型。不得不吐槽一下,解决英文代码错误之类的问题,还是去google吧。
6.如果不出意外,你就能看到那个茶壶了。