1.首先编译osg /osgEarth 源码,配置环境变量,将osg及osgEarth 对应的bin目录加入系统环境中。
2.在QT中的pro文件中进行引用:
include(deployment.pri)
win32:INCLUDEPATH +=C:/OSGEARRH/include \
C:/OpenSceneGraph/include \
win32:DEPENDPATH +=C:/OSGEARRH/include \
C:/OpenSceneGraph/include
win32:CONFIG(release, debug|release): LIBS += \
-LC:/OSGEARRH/lib/ -losgEarth \
-LC:/OSGEARRH/lib/ -losgEarthAnnotation \
-LC:/OSGEARRH/lib/ -losgEarthFeatures \
-LC:/OSGEARRH/lib/ -losgEarthQt \
-LC:/OSGEARRH/lib/ -losgEarthSymbology \
-LC:/OSGEARRH/lib/ -losgEarthUtil \3.在CPP文件编写
一般我们加载和使用对应的地理信息资源需要以下几步:
源码如下:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
int main( int argc, char** argv )
{
QApplication app(argc, argv);
osgQt::initQtWindowingSystem();
//osg::Group* sceneroot = new osg::Group;
osg::ref_ptr<osgEarth::Map> map= new osgEarth::Map;
osg::ref_ptr<osgEarth::MapNode> mapNode= new osgEarth::MapNode(map);
osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
osgEarth::Drivers::TMSOptions tms;
tms.url()="D:/data/world/tms.xml";
map->addImageLayer(new osgEarth::ImageLayer("My",tms));
viewer->addEventHandler(new osgViewer::StatsHandler);
viewer->addEventHandler(new osgGA::StateSetManipulator());
viewer->setCameraManipulator( new osgGA::TrackballManipulator );
viewer->setSceneData(mapNode);
osgQt::setViewer( viewer.get() );
osgQt::GLWidget* glw = new osgQt::GLWidget;
osgQt::GraphicsWindowQt* graphicswin = new osgQt::GraphicsWindowQt(glw);
viewer->getCamera()->setViewport( new osg::Viewport(0, 0, glw->width(), glw->height() ) );
viewer->getCamera()->setGraphicsContext( graphicswin );
glw->show();
return app.exec();
}运行结果如下: