#构建osgEarth

此处的文档主要针对Windows。

##使用vcpkg构建

[vcpkg] (https://github.com/Microsoft/vcpkg)是一个非常有用的包管理器。它可以在Windows、Linux和MacOS上运行,但在本指南中,我们将重点介绍Windows。

Step 1 - Configure vcpkg

首先,下载并引导 [vcpkg] (https://github.com/Microsoft/vcpkg)按照页面上的说明操作。

Step 2 - Clone the repository

从GitHub下拉源并创建 `build 您的源代码外版本的`文件夹。我们总是建议进行源代码外的构建,以避免以后出现问题!

` git clone --recurse-submodules https://github.com/gwaldron/osgearth.git osgearth mkdir build `

这会将存储库克隆到名为的文件夹中 osgearth 并拉下所有子模块。

Step 3 - Configure CMake

vcpkg提供了一个CMake工具链文件,帮助osgEarth找到它的所有依赖项。

注意:您需要根据您的构建配置(Release、RelWIthDebInfo、Debug)指定不同的构建目录,并使用 `-DCMAKE_BUILD_TYPE `。这是因为在没有指定构建类型的情况下,osgEarth的某些依赖项不会同时获取调试和发布版本。希望这个问题将在未来的CMake版本中得到修复。

大多数开发人员将使用RelWithDebInfo构建,如下所示:

` cmake -S osgearth -B build -G "Visual Studio 15 2017 Win64" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DWIN32_USE_MP=ON -DCMAKE_INSTALL_PREFIX=[installroot] -DCMAKE_TOOLCHAIN_FILE=[vcpkgroot]\scripts\buildsystems\vcpkg.cmake `

OsgEarth提供了一个vcpkg.json清单文件,其中列出了它的所有必需依赖项。Vcpkg工具链集成将注意到此文件,并在您的Buildvcpkg_Installed目录中安装必要的依赖项。

Step 4 - Build and install osgEarth

您可以使用CMake在命令行上构建和安装osgEarth,也可以打开Visual Studio解决方案并从那里构建它。

` cmake --build build --target INSTALL --config RelWithDebInfo `

Step 5 - Set up your runtime environment

您需要确保vcpkg依赖项和osgEarth位于您的路径中:

` set PATH=%PATH%;path\to\build\vcpkg_installed\x64-windows\bin set PATH=%PATH%;path\to\build\vcpkg_installed\x64-windows\tools\osg set PATH=%PATH%;[installroot] `

##构建不同OpenGL配置文件最新版本(截止2022年4月21日)vcpkg默认使用OpenGL_PROFILE=GL3构建OSG。这对于运行osgEarth应该足够了,因为它启用了所有现代OpenGL功能,并禁用了OSG中过时的固定函数管道路径。

If you wish to build OSG with a different OPENGL_PROFILE such as GLCORE you can use a custom triplet variable by modifying the existing x64-windows.cmake triplet file at pathtovcpkgtripletsx64-windows.cmake and adding a new variable to end of the file like this ` set(osg_OPENGL_PROFILE GLCORE) ` When you install osg using vcpkg with this variable set it will build osg against the <GL/glcorearb.h> headers instead of the usual <GL/gl.h> header.

##检查OpenGL核心配置文件上下文某些情况要求您具有OpenGL核心配置文件上下文。当使用OpenGL_PROFILE=GL3或GLCORE构建OSG时,可以创建核心上下文。Apple OSX和VMWare等环境需要它,使用Nvidia NSight等工具进行调试也是如此。通过运行如下所示的命令(Windows),可以检查是否使用OpenGL Core配置文件运行 ``` set OSG_GL_CONTEXT_VERSION=4.6 osgearth_version --caps `` `

如果一切顺利,它应该报告 "Core Profile = yes"

您可以禁用核心配置文件并选择兼容性配置文件,方法是设置配置文件掩码,如下所示

` set OSG_GL_CONTEXT_PROFILE_MASK=1 `

上下文版本和配置文件掩码也可以通过 osg::DisplaySettings 类在OpenSceneGraph API中创建。

##VMware用户小贴士

在虚拟机环境中运行osgEarth可能很棘手,因为默认情况下,它们通常不能直接访问图形硬件。如果你有困难,你可以试试这些小贴士。

首先,为GL核心配置文件构建OSG和osgEarth(如上所述)。

接下来,使用功能检查评估情况:

` osgearth_version --caps `

输出将如下所示:

` GPU Vendor:        WMware, Inc. GPU Renderer       Gallium 0.3 on llvmpipe GL/Driver Version: 1.2 Mesa 11.2.0 `

如果IS报告MESA驱动程序,并且版本低于3.3,则需要配置几个环境变量才能继续(Windows):

` set OSG_GL_CONTEXT_VERSION=3.3 set MESA_GL_VERSION_OVERRIDE=3.3 osgearth_version --caps `

祝你好运!