欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

OpenSceneGraph编译

程序员文章站 2023-12-25 12:24:21
...

初学OSG,第一件事情就是编译,经过几天的折腾,那只五光十色的奶牛终于见面了。一向比较头疼编译这件事情,编译成功前觉得遥不可及,编译成功后觉得易如反掌。既然编过了,做个笔记,备忘。

1. 准备源码和工具

1. OpenSceneGraph-3.6.2
   http://www.openscenegraph.org/index.php/download-section/stable-releases/

2. 3rdParty_VS2017_v141_x64_V11_small.7z
   http://www.openscenegraph.org/index.php/download-section/dependencies/

3. OpenSceneGraph-Data-3.4.0.zip
   http://www.openscenegraph.org/index.php/download-section/data/

2. Visiual Studio 2017 x64
   https://visualstudio.microsoft.com/zh-hans/downloads/

3. cmake-3.12.1-win64-x64.msi
   https://cmake.org/download/

4. qt-opensource-windows-x86-5.9.6.exe
   http://download.qt.io/archive/qt/5.9/5.9.6/

5. qt-vsaddin-msvc2017-2.2.1.vsix
   http://download.qt.io/archive/vsaddin/

2. 通过Cmake生成VS工程

三个文件夹:一个源码,一个三方库,一个模型数据,如下所示:

OpenSceneGraph编译

在源码目录中创建要给build目录,用于构建,如下:

OpenSceneGraph编译

修改CMakeLists.txt,添加两行,如下:

#
# OpenSceneGraph CMake build file
#
SET(OPENSCENEGRAPH_MAJOR_VERSION 3)
SET(OPENSCENEGRAPH_MINOR_VERSION 6)
SET(OPENSCENEGRAPH_PATCH_VERSION 2)
SET(OPENSCENEGRAPH_SOVERSION 157)

# add 2 lines below:
SET(DESIRED_QT_VERSION "5.9.6" CACHE STRING "")
SET(CMAKE_PREFIX_PATH "C:/Qt/Qt5.9.6/5.9.6/msvc2017_64" CACHE PATH "") 

启动CMake,配置源码目录和构建目录,并正确设置配置项,如下:

OpenSceneGraph编译

点击”Configure“,成功后点击”Generate“,成功后点击”Open Project“,启动Visiual Studio 2017,准备开始编译。

3. 编译

启动工程后选择“批生成”,如下:

OpenSceneGraph编译

打两个钩,点击“生成”,睡一觉醒来就完成了,250个成功,0个失败。

如果失败了,那也没办法。

4. 将OSG添加到系统环境变量

OSG_INCLUDE_DIR:
E:\OSG\source\OpenSceneGraph-3.6.2\OpenSceneGraph\include
E:\OSG\source\OpenSceneGraph-3.6.2\OpenSceneGraph\build\include

PATH:
E:\OSG\source\OpenSceneGraph-3.6.2\OpenSceneGraph\build\bin
E:\OSG\source\OpenSceneGraph-3.6.2\3rdparty\bin
E:\OSG\source\OpenSceneGraph-3.6.2\OpenSceneGraph\build\lib

OSG_FILE_PATH:
E:\OSG\source\OpenSceneGraph-3.6.2\OpenSceneGraph-Data

5. 运行example

OpenSceneGraph编译

OpenSceneGraph编译

6. 编写HelloWorld

#include <Windows.h>

#include<osgViewer/Viewer>
#include<osgDB/ReadFile>
int main()
{
	osgViewer::Viewer viewer;
	viewer.setSceneData(osgDB::readNodeFile("cow.osg"));

	return viewer.run();
}

注意下面说明,否则欲哭无泪:

OpenSceneGraph编译

OpenSceneGraph编译

OpenSceneGraph编译

最最重要的一行代码是:

#include <Windows.h>

否则将会抛出一大堆的未定义错误:

OpenSceneGraph编译

Ctrl + F5运行,奶牛出来,你就成功了:

OpenSceneGraph编译

睡觉了,晚安!

上一篇:

下一篇: