简介 OSGEarth是一个开源的地理空间软件库,它基于著名的3D图形工具库OpenSceneGraph(OSG)。OSGEarth主要用于创建地理空间可视化应用程序,包括地球模拟、地图浏览、地理信息系统(GIS)数据可视化等。它利用OpenSceneGraph提供的3D图形渲染能力,允许开发者构建高性能、高质量的地理空间3D可视化效果。
OSGEarth是一个开源的地理空间软件库,它基于著名的3D图形工具库OpenSceneGraph(OSG)。OSGEarth主要用于创建地理空间可视化应用程序,包括地球模拟、地图浏览、地理信息系统(GIS)数据可视化等。它利用OpenSceneGraph提供的3D图形渲染能力,允许开发者构建高性能、高质量的地理空间3D可视化效果。
1. 使用vcpkg安装(推荐) 安装vcpkg microsoft/vcpkg: C++ Library Manager for Windows, Linux, and MacOS (github.com)
使用vcpkg管理C++项目依赖 | xd’s blog (jinianyoushang.github.io)
修改vcpkg中osg的配置文件 由于osgEarth需要osg支持GL3 或者GLCORE模式,即核心模式
可以修改vcpkg中以下文件path\to\vcpkg\triplets\x64-windows.cmake
,添加下列配置
1 set(osg_OPENGL_PROFILE GL3)
安装osg 和osgEarth 1 vcpkg install osg osgearth
如果要完全安装osg 和osgearth所有组件,则可以执行
1 vcpkg install osgearth[blend2d,default-features,tools] osg[collada,default-features,docs,examples,fontconfig,nvtt,openexr,packages,plugins,sdl1,tools] osg-qt gdal osg-qt
在Visual studio中使用 vcpkg默认会配置好依赖,直接使用即可
在cmake项目使用 注意,编译器要选择msvc
在CMakeLists中配置vcpkg,需要注意把vcpkg的配置信息放在project之前,如下
1 2 3 4 5 6 7 cmake_minimum_required (VERSION 3.21 .0 )set (VCPKG_ROOT "E:/vcpkg" ) set (CMAKE_TOOLCHAIN_FILE "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" )project (MyProject LANGUAGES CXX)...
查找osg osgearth 1 2 3 4 5 find_package (OpenSceneGraph REQUIRED osg osgGA osgDB osgViewer osgUtil osgText osgVolume osgTerrain osgSim osgFX osgAnimation osgManipulator osgParticle )
链接 1 2 3 4 target_link_libraries ( ${PROJECT_NAME} ${OPENSCENEGRAPH_LIBRARIES} )
一个简单的例子 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 cmake_minimum_required (VERSION 3.20 )set (VCPKG_ROOT "C:/softwares/vcpkg-master" ) set (CMAKE_TOOLCHAIN_FILE "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" )project (simple_earth)add_compile_options ("$<$<C_COMPILER_ID:MSVC>:/utf-8>" )add_compile_options ("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>" )set (CMAKE_CXX_STANDARD 17 )find_package (OpenSceneGraph REQUIRED osg osgGA osgDB osgViewer osgUtil osgText osgVolume osgTerrain osgSim osgFX osgAnimation osgManipulator osgParticle ) include_directories (${OPENSCENEGRAPH_INCLUDE_DIRS} )message (STATUS "OpenSceneGraph Include Directories: ${OPENSCENEGRAPH_INCLUDE_DIRS}" )find_package (osgEarth CONFIG REQUIRED)add_executable (${PROJECT_NAME} main.cpp)target_link_libraries (${PROJECT_NAME} ${OPENSCENEGRAPH_LIBRARIES} ) if (CMAKE_BUILD_TYPE STREQUAL "Debug" ) message ("Debug build" ) target_link_libraries (${PROJECT_NAME} ${osgEarth_LIBRARIES_DEBUG} ) elseif (CMAKE_BUILD_TYPE STREQUAL "Release" ) message ("Release build" ) target_link_libraries (${PROJECT_NAME} ${osgEarth_LIBRARIES} ) else () message ("Unknown build type: ${CMAKE_BUILD_TYPE}" ) target_link_libraries (${PROJECT_NAME} ${osgEarth_LIBRARIES} ) endif ()message (STATUS ${osgEarth_LIBRARIES_DEBUG} )message (STATUS ${osgEarth_LIBRARIES} )
main.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 #include <osgViewer/Viewer> #include <osgEarth/Notify> #include <osgEarth/EarthManipulator> #include <osgEarth/MapNode> #include <osgEarth/Threading> #include <osgEarth/ShaderGenerator> #include <iostream> #include <osgEarth/Metrics> #include <osgEarth/GDAL> #include <osgEarth/XYZ> using namespace osgEarth;using namespace osgEarth::Util;#include <string> #include <iostream> using namespace std;int main () { osg::setNotifyLevel (osg::DEBUG_FP); osgEarth::initialize (); osgViewer::Viewer viewer; viewer.setUpViewInWindow (0 , 100 , 800 , 600 ); viewer.setReleaseContextAtEndOfFrameHint (false ); viewer.setCameraManipulator (new EarthManipulator); osg::ref_ptr<osgEarth::Map> rootMap = new osgEarth::Map; osg::ref_ptr<XYZImageLayer> someLayer = new XYZImageLayer; someLayer->setURL (osgEarth::URI ("http://[abc].tile.openstreetmap.org/{z}/{x}/{y}.png" )); someLayer->setProfile (osgEarth::Profile::create (Profile::SPHERICAL_MERCATOR)); osg::ref_ptr<osgEarth::MapNode> rootMapNode = new osgEarth::MapNode (rootMap.get ()); rootMap->addLayer (someLayer); viewer.setSceneData (rootMapNode); return Metrics::run (viewer); }
2.手动编译安装 待完成
参考 第23节 编译-《OSG&OE编译一本通V1.42》永久性解决编译问题_osg和oe-CSDN博客