Preface:

Friends do Qt with OSG development, their local configuration OSG tried, wasted a day, headache. Make a note of it for future partners.

Prepare the software environment before compilation:

1, Windows10 system

2, CMake (latest version)

3, VS2017 (OSG official website supporting third-party library, the highest only to 2017 this version)

4. Git (latest version)

As for the hardware, the higher the configuration, the better (mine is i7 10700K, OSG to compile three hours, day!)

Prepare the source code before compiling:

Go to [website](Home (openscenegraph.org)Download [source code](Lot – openscenegraph/openscenegraph at openscenegraph – 3.6.5), third party libraries and data resources (resources download even take three TMD!! Day!)

Download the latest version of the source code (when I downloaded 3.6.5)

After the download, put the decompressed folder into the D:\OSG directory, this is the source code and resources downloaded after the screenshot:

However, I saw that X64 was not comfortable, so I changed 3rdParty_x64 to 3rdParty, and moved up the files in the x64 directory under its directory, and then deleted the x64 empty folder. This picture looks like:

Change this image to look like:

At this point, the source file is ready to end.

Build process:

1, open cmake-gui, drag D:\OSG\OpenSceneGraph\ cMakelists. TXT to cmake-GUI interface, add a layer /build directory after the make directory, click configure. Select VS2017, Optional Platform for Generator, enter X64, and click Finish.

2. Finish The configuration.

ACTUAL_3RDPARTY_DIR: D: / OSG / 3 rdparty

BUILD_OSG_EXAMPLES: hook

CMAKE_INSTALL_PREFIX: D: / OSG/OpenSceneGraph /

Click Configure.

3. Check BUILD_MFC_ EXAMPLE and click Configure.

4, click Generate to complete the build, and then close cmake-GUI.

Compilation process:

Openscenegraph.sln (D:\OSG\OpenSceneGrap\build)

2. On the menu bar, click “Build” and “Batch Build”, select Debug and Release corresponding to ALL_BUILD, and click “Build”. The generation process is super TM long, about two hours.

Note: During the compilation process, I will encounter some errors, and I will search for the answers (I only encountered two, below), such as:

#include “algorithm”, #include “algorithm”, #include “algorithm”, #include “algorithm”, #include “algorithm”

② “LCMapStringEx” : the identifier is not found. The generated stdafx.h header file is added

#define _WIN32_WINNT 0x0A00
#define _ATL_APARTMENT_THREADED
#define _USING_V110_SDK71_
#define _ATL_XP_TARGETING
Copy the code

Examples OSgSimpleGL3 and Examples osgviewerMFC are both required for Debug and Realse

_WIN32_WINNT=0x0A00
NTDDI_VERSION= 0x06030000
WINVER=0x0A00
Copy the code

Finally, the compilation succeeds.

3. On the menu bar, click “Build”, “batch build”, select Debug and Release of INSTALL, and click “Build”.

Usage process:

D:\OSG\OpenSceneGraph\bin \ D:\OSG\OpenSceneGraph\build\bin \ D:\OSG\3rdParty\bin \ D:\OSG\3rdParty\bin \Note, three paths!!)

D:\OSG\ openscenegraph-data

3. Open CMD and enter commands

Osgversion # will output the version number osgViewer cow. Osg # will output a cow image, press the Esc key on the keyboard to exit osglogo # will output an English logo, press the Esc key on the keyboard to exitCopy the code

Verify.

Code verification:

Create a new VS2017 C++ project, add a new. CPP file, enter the code:

#include <osgViewer/Viewer>
#include <osgDB/ReadFile>
 
int main(int argc, char **argv)
{
	osgViewer::Viewer viewer;
	viewer.setSceneData(osgDB::readNodeFile("cow.osg"));
	return viewer.run();
}
Copy the code

Configuration: X64, Debug,

D:\OSG\OpenSceneGraph\include;

D:\OSG\OpenSceneGraph\lib;

③ To reference the lib library, enter:

OpenThreadsd.lib 
osgd.lib 
osgDBd.lib 
osgUtild.lib 
osgGAd.lib 
osgViewerd.lib 
osgTextd.lib
Copy the code

(4) Click the keyboard F5 to compile and run, it will pop up the cow image above, click the Esc key to exit.

That’s all. Thank you for taking your time.