測試了一天,終於能在Linux的QT環境下編寫OpenGL程序了。
我原先認爲Linux下的qt跟windows下的qt一樣,裝好qt後,openGL的庫也裝好了。只要包含頭文件,就可以調用openGL的函數了。事實上,Linux的qt creator安裝好後,雖然包含有openGL的頭文件,但openGL庫函數模塊並沒有包括在其中,還需另外安裝。
Ubuntu下安裝openGL庫:
sudo apt-get install libgl-dev libglu-dev
我終端輸如後提示
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package libgl-dev is a virtual package provided by:
libgl1-mesa-swx11-dev 7.7.1-1ubuntu3
libgl1-mesa-dev 7.7.1-1ubuntu3
You should explicitly select one to install.
E: Package libgl-dev has no installation candidate
libgl1-mesa-swx11-dev 7.7.1-1ubuntu3
libgl1-mesa-dev 7.7.1-1ubuntu3
both direct and indirect rendering. For direct rendering, it can use DRI
modules from the libgl1-mesa-dri package to accelerate drawing.
libgl1-mesa-swx11-dev: This library provides a pure software rasteriser; it does not provide
a direct rendering-capable library, or one which uses GLX. For that,
please see libgl1-mesa-dev.
我的做法是在*.pro中使 QT += opengl ,這樣也能實現