python opengl_Python环境搭建之OpenGL
以下內容為我python OpenGl 環境搭建歷程:
win7 64位操作系統,python3.5.3 ,無其他相關。
直接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,進行安裝。。。
失敗,提示需要.net framework4.5.1以上
一開始我下載了.net framework 4.5 發現還不能安裝,于是重新搜索,終于在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)了。
經過漫長的等待VC++也搞定,重啟后繼續執行命令:
pip install PyOpenGL PyOpenGL_accelerate
一次性成功,興奮之余在網上找了段測試代碼,并稍作調整(?glutCreateWindow(b"first")處,原文為glutCreateWindow("first"),運行會報錯:)
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")#調用函數繪制圖像
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位同理)。
下載解壓后將文件夾內 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 下。
再次運行,終于大功告成,可以看到一個旋轉的茶壺。
總結
以上是生活随笔為你收集整理的python opengl_Python环境搭建之OpenGL的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 大蒜有什么功效
- 下一篇: sql不等于0怎么表示_数组真的只能从0