安装PyopenGL
64位win7,
先装了anaconda,
在anaconda上创建Python3.6的环境,再搜索PyopenGL并下载。
简单算例
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
def drawFunc():
# 清楚之前画面
glClear(GL_COLOR_BUFFER_BIT)
glRotatef(0.1, 5, 5, 0) # (角度,x,y,z)
glutWireTeapot(0.5)
# 刷新显示
glFlush()
# 使用glut初始化OpenGL
glutInit()
# 显示模式:GLUT_SINGLE无缓冲直接显示|GLUT_RGBA采用RGB(A非alpha)
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA)
# 窗口位置及大小-生成
glutInitWindowPosition(0, 0)
glutInitWindowSize(400, 400)
glutCreateWindow(b"first")
# 调用函数绘制图像
glutDisplayFunc(drawFunc)
glutIdleFunc(drawFunc)
# 主循环
glutMainLoop()
出现问题
OpenGL.error.NullFunctionError: Attempt to call an undefined function glutInit, check for bool(glutInit) before calling
在网上找解决办法,最后在这个链接里找到了办法。
https://blog.csdn.net/renjiangui/article/details/7614616
“可能是缺少相关dll文件,可以在这里下载到 http://pan.baidu.com/s/1dFhC8G5
拷到你建立的工程目录下,就是你写的程序的目录下就可以了。”
成功运行
一个个旋转的茶壶