如下内容为我python OpenGl 环境搭建历程:python
win7 64位操做系统,python3.5.3 ,无其余相关。函数
直接cmd或PowerShell输入如下命令:oop
pip install PyOpenGL PyOpenGL_accelerate
安装失败,提示需安装Microsoft Visual C++ 14.0,让我使用Microsoft Visual C++ build tools。而且后面给出了下载连接http://landinghub.visualstudio.com/visual-cpp-build-tools,在该连接下载获得文件visualcppbuildtools_full.exe,进行安装。。。测试
失败,提示须要.net framework4.5.1以上ui
一开始我下载了.net framework 4.5 发现还不能安装,因而从新搜索,终于在https://www.microsoft.com/zh-CN/download/details.aspx?id=48130找到4.6版本,下载得文件NDP46-KB3045560-Web.exe安装之。spa
终于能够安Microsoft Visual C++ build tools(visualcppbuildtools_full.exe)了。操作系统
通过漫长的等待VC++也搞定,重启后继续执行命令:.net
pip install PyOpenGL PyOpenGL_accelerate
一次性成功,兴奋之余在网上找了段测试代码,并稍做调整( glutCreateWindow(b"first")处,原文为glutCreateWindow("first"),运行会报错:Python glutCreateWindow error 'wrong type',详情参见https://codeyarns.com/2012/04/27/pyopengl-glut-ctypes-error/ )code
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。原来我没搭建glut,又开始漫长的搜寻路程,终于在http://download.csdn.net/detail/knownall/6799947找到须要的(其实就须要glut.h、glut64.dll、glut64.lib三个文件,32位同理)。blog
下载解压后将文件夹内 glut.h 放在 C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\ 下;
将 .\Release\glut64.lib 放在 C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib\ 下;
将 .\Release\glut64.dll 放在 C:\Windows\System32 下。
再次运行,终于大功告成,能够看到一个旋转的茶壶。