osg安装配置以及运行实例(arch linux)

1 下载源码进行编译

(大致参照https://vicrucann.github.io/tutorials/osg-linux-quick-install/)

git clone https://github.com/openscenegraph/OpenSceneGraph.git
git checkout -b 3.6 origin/OpenSceneGraph-3.6
mkdir build
cd build
cmake ..
make -j8
make install

这个时候根据你的make install的结果判断你的osg安装在什么位置,
我的是位于: /usr/local/include, /usr/local/lib, /usr/local/bin
将这三个路径添加到$PATH中,vim /etc/profile,在其尾部添加如下代码:

# set the osg env path:
export LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH"
export OPENTHREADS_INC_DIR="/usr/local/include"
export OPENTHREADS_LIB_DIR="/usr/local/lib"
export PATH="/usr/local/share:$OPENTHREADS_LIB_DIR:$OPENTHREADS_INC_DIR:$PATH"

验证库的位置:

[nash5 home]# ls /usr/local/include/ | grep osg
osg
osgAnimation
osgDB
osgFX
osgGA
osgManipulator
osgParticle
osgPresentation
osgShadow
osgSim
osgTerrain
osgText
osgUI
osgUtil
osgViewer
osgVolume
osgWidget

2 下载实例数据:

osg -> http://www.openscenegraph.org/index.php/download-section/data

3 测试:

osgviewer ../BASE_ENV/OpenSceneGraph-Data/cow.osg

使用如下代码测试:
CMakeLists.txt

cmake_minimum_required(VERSION 3.13)  # CMake version check
project(osgWeb)               # Create project "simple_example"
set(CMAKE_CXX_STANDARD 14)            # Enable c++14 standar
# Add main.cpp file of project root directory as source file
set(SOURCE_FILES test.cpp)

# set the emscripten's dir and lib
include_directories(/home/nash5/BASE_ENV/emsdk/upstream/emscripten/system/include)
include_directories(/usr/local/include)

link_directories(/usr/local/lib)

# Add executable target with source files listed in SOURCE_FILES variable
add_executable(test.out ${SOURCE_FILES})
target_link_libraries(test.out libosgDB.so libosgViewer.so)

test.cpp


#include <iostream>
#include <osgDB/ReadFile>
#include <osg/Node>
#include <osgViewer/Viewer>

int main()
{
    std::cout << "Hello World!\n";
   std::string modelPath = "/home/nash5/BASE_ENV/OpenSceneGraph-Data/cessna.osg";
   osgViewer::Viewer viewer;
   viewer.setSceneData(osgDB::readNodeFile(modelPath));
   viewer.realize();
   viewer.run();
    std::cout << "Hello World!\n";
}

或者不使用CMakeLists.txt,直接使用g++编译:

g++ a.cpp -losgDB -losgViewer -o a.out
./a.out
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值