1.在GitHub上下载OpenSceneGrpah的源码包,。
2.解压缩源码包并进入源码包;
3.安装所需的依赖库:
先输入命令:
sudo apt-get install openscenegraph
再次执行cmake . 后依然会提示缺少很多依赖库,依次手动安装:
egl:libgles2-mesa-dev
freetype:libfreetype6-devjpeg:libjpeg-devfltk:fltk1.3-devcurl:libopenssl-devgstreamer:libgstreamer-plugins-base1.0-devgdal:libgdal-devsdl2:libsdl2-devsdl:libsdl1.2-devwxWidget:libwxgtk3.0-devtiff:libtiff-dev用法:sudo apt install "package",将“package”替换为以上冒号后的库名即可。4.再次执行以下命令:
cmake .makesudo make install
5.配置环境变量
在home路径下,编辑.bashrc。在文件末尾添加如下变量:
export PATH = “${PATH}:/home/junerain/project/OpenSceneGraph/bin”export LD_LIBRARY_PATH = “${LD_LIBRARY_PATH}:/home/junerain/project/OpenSceneGraph/lib” export OSG_FILE_PATH = “/home/**********/OpenSceneGraph-Data:/home/*********/OpenSceneGraph-Data/Images”
根据自己的电脑,将星号内容替换为下载的测试数据文件夹所在路径。之后执行source ./bashrc 使其生效。
6.测试
在命令行输入以下命令:
osgversion #yield "OpenSceneGraph Library 3.7.0" in my computer
osgviewer cow.osg #display a irony cow model
或和运行源码包自带的示例程序:
sh runexample.bat
即可看到许多有趣的例子。
Enjoy!