Python環境搭建之OpenGL

2022-07-17 11:12:14 字數 1605 閱讀 1558

以下內容為我python opengl 環境搭建歷程:

win7 64位作業系統,python3.5.3 ,無其他相關。

直接cmd或powershell輸入以下命令:

pip install  pyopengl pyopengl_accelerate

失敗,提示需要.net framework4.5.1以上

終於可以安microsoft visual c++ build tools(visualcppbuildtools_full.exe)了。

經過漫長的等待vc++也搞定,重啟後繼續執行命令:

pip install  pyopengl pyopengl_accelerate

一次性成功,興奮之餘在網上找了段測試**,並稍作調整( glutcreatewindow(b"first")處,原文為glutcreatewindow("first"),執行會報錯:

python glutcreatewindow error 'wrong type',詳情參見

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,又開始漫長的搜尋路程,終於在找到需要的(其實就需要glut.h、glut64.dll、glut64.lib三個檔案,32位同理)。

將 .\release\glut64.lib 放在 c:\program files (x86)\microsoft visual studio 14.0\vc\lib\ 下;

將 .\release\glut64.dll 放在 c:\windows\system32 下。

再次執行,終於大功告成,可以看到乙個旋轉的茶壺。

Python環境搭建之OpenCV

一 opencv介紹 二 環境 環境變數中加入python安裝路徑,我的是 c program files python35 scripts c program files python35 注意分號。三 開搞 一切就緒以後以管理員身份執行cmd或powershell。依次輸入以下命令 pip in...

Python環境搭建之OpenCV

一 opencv介紹 二 環境 環境變數中加入python安裝路徑,我的是 c program files python35 scripts c program files python35 注意分號。三 開搞 一切就緒以後以管理員身份執行cmd或powershell。依次輸入以下命令 pip in...

Python環境搭建之OpenCV

一 opencv介紹 二 環境 環境變數中加入python安裝路徑,我的是 c program files python35 scripts c program files python35 注意分號。三 開搞 一切就緒以後以管理員身份執行cmd或powershell。依次輸入以下命令 pip in...