一、背景
目前较为常用的osgearth版本分别为2.8,2.10,3.2,其中3.2版本最新,并且3.x版本和2.x版本差别很大,主要区别在于2.x有7个主要库,而3.x版本只有osgEarth这一个库。至于为什么2.x版本还有很多人用,因为2.x和3.x很多函数有了大幅变化,如果升级最新版本的话,代码不兼容,需要改动的地方很多,但实际功能没有明显区别。
二、代码
- #include
- #include
- #include
- #include
- #include
- #include
-
- #ifdef _DEBUG
- //osg库一共19个
- #pragma comment(lib, "osgd.lib")
- #pragma comment(lib, "osgDBd.lib")
- #pragma comment(lib, "osgFXd.lib")
- #pragma comment(lib, "osgViewerd.lib")
- #pragma comment(lib, "osgVolumed.lib")
- #pragma comment(lib, "OpenThreadsd.lib")
- #pragma comment(lib, "osgGAd.lib")
- #pragma comment(lib, "osgUtild.lib")
- #pragma comment(lib, "osgManipulatord.lib")
- #pragma comment(lib, "osgTextd.lib")
- #pragma comment(lib, "osgSimd.lib")
- #pragma comment(lib, "osgTerraind.lib")
- #pragma comment(lib, "osgWidgetd.lib")
- #pragma comment(lib, "osgUId.lib")
- #pragma comment(lib, "osgShadowd.lib")
- #pragma comment(lib, "osgAnimationd.lib")
- #pragma comment(lib, "osgParticled.lib")
- #pragma comment(lib, "osgPresentationd.lib")
- #pragma comment(lib, "osgQOpenGLd.lib")
- //osgearth库1个
- #pragma comment(lib, "osgEarthd.lib")
- //其他库2个
- #pragma comment(lib, "glu32.lib")
- #pragma comment(lib, "opengl32.lib")
- #else
- #pragma comment(lib, "osg.lib")
- #pragma comment(lib, "osgDB.lib")
- #pragma comment(lib, "osgFX.lib")
- #pragma comment(lib, "osgViewer.lib")
- #pragma comment(lib, "osgVolume.lib")
- #pragma comment(lib, "OpenThreads.lib")
- #pragma comment(lib, "osgGA.lib")
- #pragma comment(lib, "osgUtil.lib")
- #pragma comment(lib, "osgManipulator.lib")
- #pragma comment(lib, "osgText.lib")
- #pragma comment(lib, "osgSim.lib")
- #pragma comment(lib, "osgTerrain.lib")
- #pragma comment(lib, "osgWidget.lib")
- #pragma comment(lib, "osgUI.lib")
- #pragma comment(lib, "osgShadow.lib")
- #pragma comment(lib, "osgAnimation.lib")
- #pragma comment(lib, "osgParticle.lib")
- #pragma comment(lib, "osgPresentation.lib")
- #pragma comment(lib, "osgQOpenGL.lib")
-
- #pragma comment(lib, "osgEarth.lib")
-
- #pragma comment(lib, "glu32.lib")
- #pragma comment(lib, "opengl32.lib")
- #endif;
-
-
- int main(int argc, char** argv)
- {
- osgEarth::initialize();
- osgViewer::Viewer *viewer=new osgViewer::Viewer;
- //添加状态事件,可以相应键盘和鼠标事件,响应L T B W
- viewer->addEventHandler(new osgGA::StateSetManipulator(viewer->getCamera()->getOrCreateStateSet()));
- //窗口大小变化,响应F
- viewer->addEventHandler(new osgViewer::WindowSizeHandler);
- //添加路径记录 Z
- viewer->addEventHandler(new osgViewer::RecordCameraPathHandler);
- //帮助文档显示H
- viewer->addEventHandler(new osgViewer::HelpHandler);
- //截屏 C
- viewer->addEventHandler(new osgViewer::ScreenCaptureHandler);
- //添加一些常用状态设置,响应S
- viewer->addEventHandler(new osgViewer::StatsHandler);
- viewer->setCameraManipulator(new osgEarth::Util::EarthManipulator);
-
- osg::Group* root = new osg::Group;
- root->addChild(osgDB::readNodeFile("simple.earth"));
- viewer->setSceneData(root);
- return viewer->run();
- }
三、库下载
链接:https://pan.baidu.com/s/1VMDbP8UeufZ63jTRPKzp-w?pwd=8888
提取码:8888