OSG entry refers to the detailed steps for osgearth to build a earth
Turn: http://blog.csdn.net/xiaol_deng/article/details/9246291
I recently learned about OSG, But I was confused at the beginning. Fortunately, I was very confused under the guidance of my teacher. At the same time, I also summarized multiple pieces of information on the Internet.
Experience as a beginner. Hope that the majority of beginners will not take a detour!
Before you start OSG programming, you need to prepare OSG compilation. Here, as a beginner, it is best to choose a simple method to familiarize yourself with it first. We first download a compiled vs2010 + osgearth. Note that there may be a lot of puzzles here. I thought so at the time, and we will implement it step by step.
Step 1: Download the compilation package
Osg3.1.4 and osgear2.3 VC10 compilation packages
:
Http://pan.baidu.com/share/link? Consumer id = 107009 & UK = 2801833827
Step 2: create a directory
Create a directory in your hard disk. I will create an osgearth directory on the E disk and copy the downloaded compressed package to E: \ osgearth \
Decompress and decompress the package. The files in E: \ osgearth \ OSG are shown in:
Step 3: Set Environment Variables
As a beginner, I encountered a lot of trouble in this step. In order not to let everyone repeat the same mistakes, we will introduce them in detail here.
1. How to Set Environment Variables
Right-click my computer-> properties, as shown in:
Here is the "advanced" tab, as shown in:
After completing the preceding steps, the following error occurs:
Here is the "environment variable" option below, as shown in:
This will show:
2. Set specific environment variable values
The environment variable value we set is in the system variable,
At this time, I want to click "new" to create the corresponding options, and then the variable name: osg_root variable value: e: \ osgearth \ OSG the variable value here is determined based on the directory you created, and then confirm it. After creating a new item, we also need to create several options in the same way: (1) variable name: osg_file_path variable value: e: \ osgearth \ OSG \ data note that this is also based on the specific situation
(2) variable name: osg_window
Variable value: 600 15 800 800 note that this value can be fixed and is irrelevant.
After completing the preceding steps, the next step is somewhat different. This time, instead of creating a new one, we will edit the option content. The edited options are shown in:
You can see that the "Edit path" option is selected, and then click the edit key below to change the variable value to E: \ osgearth \ OSG \ bin. Note that I have changed the value here, it may not matter if you are at the beginning. After these changes, click OK until you exit the environment variable settings.
Step 4: Set file directory Properties
Open vs2010 to create a console application named osgvr, and then set it,
②
Set project properties to add directories containing files and libraries
Here, only the debug version is set as an example. The release version is similar to this one.
NOTE: For the debug version, enter the Lib file name suffix for the linker, Which is d more than the release version, indicating the debug version,
Right-click the menu and select "properties"
The "configuration (c)" item indicates whether to debug or release, and select
You need to set three items, including the file directory include, the Lib library file directory and the linker.
The attached dependency is, And osgearth is not added.
[Plain]View plaincopy
- Openthreadsd. Lib
- Osgd. Lib
- Osgdbd. Lib
- Osgfxd. Lib
- Osggad. Lib
- Osgmanipulatord. Lib
- Osgparticipant. Lib
- Osgshadowd. Lib
- Osgsimd. Lib
- Osgterraind. Lib
- Osgtextd. Lib
- Osgutild. Lib
- Osgviewerd. Lib
Step 5: write code
Print?
- # Include "stdafx. H"
- # Include <osgviewer/Viewer>
- # Include <OSG/node>
- # Include <OSG/geode>
- # Include <OSG \ group>
- # Include <osgdb/readfile>
- # Include <osgdb/writefile>
- # Include <osgutil \ optimizer>
- Int _ tmain (INT argc, _ tchar * argv [])
- {
- OSG: ref_ptr <osgviewer: viewer> viewer = new osgviewer: Viewer ();
- OSG: ref_ptr <OSG: group> root = new OSG: group ();
- OSG: ref_ptr <OSG: node> node = osgdb: readnodefile ("mymap. Earth ");
- Root-> addchild (node. Get ());
- Osgutil: optimizer;
- Optimizer. Optimize (root. Get ());
- Viewer-> setscenedata (root. Get ());
- Viewer-> realize ();
- Viewer-> Run ();
- Return 0;
- }
After writing this code, you need to write the mymap. Earth file. Here, you can use Notepad ++ to edit the file. The content is as follows:
- <Map Name = "mymap" type = "geocentric" version = "2">
- <Image name = "bluemarble" driver = "gdal">
- <URL> world. tif </URL>
- </Image>
- </Map>
Edit mymap. copy the earth file to the directory where your project is located. The depth is the same as mine: e: \ vs2010progam files \ osgvr74 \ osgvr74. tif file and mymap. earth is under the same level directory.
You can compile and execute these tasks as follows:
OSG entry refers to the detailed steps for osgearth to build a earth