python opengl_Python环境搭建之OpenGL
以下內(nèi)容為我python OpenGl 環(huán)境搭建歷程:
win7 64位操作系統(tǒng),python3.5.3 ,無其他相關(guān)。
直接cmd或PowerShell輸入以下命令:
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,進(jìn)行安裝。。。
失敗,提示需要.net framework4.5.1以上
一開始我下載了.net framework 4.5 發(fā)現(xiàn)還不能安裝,于是重新搜索,終于在https://www.microsoft.com/zh-CN/download/details.aspx?id=48130找到4.6版本,下載得文件NDP46-KB3045560-Web.exe安裝之。
終于可以安Microsoft Visual C++ build tools(visualcppbuildtools_full.exe)了。
經(jīng)過漫長的等待VC++也搞定,重啟后繼續(xù)執(zhí)行命令:
pip install PyOpenGL PyOpenGL_accelerate
一次性成功,興奮之余在網(wǎng)上找了段測(cè)試代碼,并稍作調(diào)整(?glutCreateWindow(b"first")處,原文為glutCreateWindow("first"),運(yùn)行會(huì)報(bào)錯(cuò):)
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
defdrawFunc():#清楚之前畫面
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")#調(diào)用函數(shù)繪制圖像
glutDisplayFunc(drawFunc)
glutIdleFunc(drawFunc)#主循環(huán)
glutMainLoop()
運(yùn)行,結(jié)果提示OpenGL.error.NullFunctionError: Attempt to call an undefined function glutInit, check for bool(glutInit) before calling。原來我沒搭建glut,又開始漫長的搜尋路程,終于在http://download.csdn.net/detail/knownall/6799947找到需要的(其實(shí)就需要glut.h、glut64.dll、glut64.lib三個(gè)文件,32位同理)。
下載解壓后將文件夾內(nèi) 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 下。
再次運(yùn)行,終于大功告成,可以看到一個(gè)旋轉(zhuǎn)的茶壺。
總結(jié)
以上是生活随笔為你收集整理的python opengl_Python环境搭建之OpenGL的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。