Stop reading other OSG configuration tutorials, the most complete ones are here! —— VisualStudio2017+QT5.14.2+OSG3.6.4 download and compile

Before reading this tutorial, first make sure your environment isVS2017QT5.14.2OSG3.6.4! ! ! ! ! ! ! ! ! ! ! !
Before reading this tutorial, first make sure your environment isVS2017QT5.14.2OSG3.6.4! ! ! ! ! ! ! ! ! ! ! !
Before reading this tutorial, first make sure your environment isVS2017QT5.14.2OSG3.6.4! ! ! ! ! ! ! ! ! ! ! !
Before reading this tutorial, first make sure your environment isVS2017QT5.14.2OSG3.6.4! ! ! ! ! ! ! ! ! ! ! !
Well, the important thing is said four times. . . . . . Below is the download link of all the software used in this article, and then the download address of the collection.

Download

VS2017 download address

VS2017

QT5.14.2 download address

QT 5.14.2

OSG 3.6.4 download address

OSG 3.6.4 source code
OSG 3.6.4 corresponding third-party library
optional OSG 3.6.4 data package

CMAKE download link

CMAKE (click to download directly)

Netdisk address

Collection package download

Start of text

1 Software installation

1.1 Installation of VS 2017

VS 2017 is best to use the professional version, because the professional version used by the author of VS 2017, I don't know if there will be problems with the community version, so readers are recommended to install the professional version of VS 2017.
VS 2017 Professional Edition installation process was not discussed here, but here need to be reminded that:
after installing VS 2017, in the win10 Control Panel - Programs - Uninstall be found in Windows 10 Software Development Kits , right-click the selection changes in the popup Select change in the interface, and then clickdebugger tools.
This step is for QT to automatically detect the MSVC 2017 compiler when selecting a compiler later.

1.2 Installation of QT 5.14.2

There is nothing to say about the installation of QT, just check everything when choosing the installation content, which is definitely correct.

1.3 Installation of CMAKE

There is nothing to say about the installation of CMAKE, just the next step all the way. After installation, a cmake shortcut will be created on the desktop, and you can open this shortcut directly when you use it later.

2 Compile OSG

This step is the most difficult. Many people have problems in this step, so be careful and follow this tutorial strictly! ! !
This step is the most difficult. Many people have problems in this step, so be careful and follow this tutorial strictly! ! !
This step is the most difficult. Many people have problems in this step, so be careful and follow this tutorial strictly! ! !
If you want to use OSG in QT, you must first compile the OSG source code. The LIB library generated by different compilers may not be universal. In QT, OSG is used by importing the lib library generated by compiling OSG source code, so the choice of compiler is very important.
There are only a few commonly used compilers in QT, such as MSVC 2015, MSVC 2017, MinGW, etc. The author also tried to compile OSG with MinGW, but it could not be used due to various reasons. Therefore, MSVC 2017 was chosen in the end.
The compilation process is divided into the following steps:

2.1 Decompression of OSG and OSG third-party libraries

After downloading the OSG source code and third-party library, decompress it. Insert picture description here
As shown in the figure, the author created an OSG folder on the D drive, which contains the OSG source code compression package and the third-party library compression package. After decompression, it is also placed in this directory.

2.2 Use CMake software to generate VS project

Then open the OSG source code folder, there is a CMakeLists.txt file in this directory. Open the file and add the following code snippet:

set(DESIRED_QT_VERSION "5" CACHE STRING "")
set(CMAKE_PREFIX_PATH "D:/Qt/5.14.2/msvc2017_64" CACHE PATH "")

The author's CMakeLists.txt file is as follows: After
Insert picture description here
adding these two lines of code, open the CMake software. The screenshot of the software opening is as follows:
Insert picture description here
Drag the CMakeLists.txt under the OSG source code folder directly to the Cmake software, and the result is as follows:
Insert picture description here
Modify the folder where the VS project file is generated, the author here is as follows:
Insert picture description here
These two folders in CMake are set up After clicking the configure button, a window for selecting the compiler will pop up, as shown below:
Insert picture description here
These two must be chosen right! ! ! ! ! ! ! ! ! !, Then click Finish, the following interface will appear: After all the
Insert picture description here
above settings are set, click Configure again, and there will still be a lot of red on the interface, as follows:
Insert picture description here
Don’t worry about these red ones, continue to click Configure, these red ones will disappear, then click Figure operation:
Insert picture description here
After clicking Configure, there is no red option. At this time, click the Generate button. It will look like the following picture: After
Insert picture description here
this step is over, go back to the OSG folder and check the folder you chose to generate the VS project file. The author here is OSGSourceCode_BUILD_2ND. As shown
The folder where the VS project file is generated after compilation
in the figure below: In this file, double-click OpenSceneGraph.sln to open it, and then we will open the installed VS 2017. The following interface will appear in VS 2017:
Insert picture description here
This is the entire VS project. Then the slowest step arrived.

2.3 Compile and generate OSG LIB library

Step by step as shown in the figure below:

  1. Right-click the solution and select batch generation.
    Insert picture description here
  2. In the pop-up interface, check the following two items: After
    Insert picture description here
    clicking "Generate", the long compilation starts. The length of this process depends on the machine configuration, the author basically compiles for more than two hours.

After this step is over, this tutorial is almost over.

3 Test if OSG is available

When opening QT, creating a new project, and selecting a compiler,Please choose MSVC 2017 64-bit.
Then import the required lib library and enter the following test code:

#include <QCoreApplication>

#include <osgViewer/Viewer>
#include <osgDB/ReadFile>

using namespace osg;
using namespace osgViewer;
using namespace osgDB;

int main(int argc, char *argv[])
{
    
    
    QCoreApplication a(argc, argv);

    ref_ptr<Viewer> viewer = new Viewer;
    viewer->setSceneData(readNodeFile("D:/OSG/OSGData/cow.osg"));
    return viewer->run();
}

Change the path in readNodeFile in the code to the path of your own data.
After running, the following interface appears, indicating that the installation is successful:
Insert picture description here

to sum up

The OSG compilation process is very complicated, and readers must be careful when compiling OSG according to this tutorial.
But no matter how careful you are, there may be some unexplained errors that cause compilation failure. Don't panic at this time, take your time. It really can't be solved, add me QQ: 805930931. (I may not be able to solve it after adding it. -.-)
If this tutorial helped you solve the problem, is it okay to follow a wave? ? ?
If this tutorial helped you solve the problem, is it okay to follow a wave? ? ?
If this tutorial helped you solve the problem, is it okay to follow a wave? ? ?
If this tutorial helped you solve the problem, is it okay to follow a wave? ? ?
If this tutorial helped you solve the problem, is it okay to follow a wave? ? ?
If this tutorial helped you solve the problem, is it okay to follow a wave? ? ?
If this tutorial helped you solve the problem, is it okay to follow a wave? ? ?
If this tutorial helped you solve the problem, is it okay to follow a wave? ? ?
If this tutorial helped you solve the problem, is it okay to follow a wave? ? ?
If this tutorial helped you solve the problem, is it okay to follow a wave? ? ?
If this tutorial helped you solve the problem, is it okay to follow a wave? ? ?
If this tutorial helped you solve the problem, is it okay to follow a wave? ? ?

Guess you like

Origin blog.csdn.net/GeomasterYi/article/details/106940761