OSG entry refers to the detailed steps for osgearth to build a earth

Source: Internet
Author: User

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
  1. Openthreadsd. Lib
  2. Osgd. Lib
  3. Osgdbd. Lib
  4. Osgfxd. Lib
  5. Osggad. Lib
  6. Osgmanipulatord. Lib
  7. Osgparticipant. Lib
  8. Osgshadowd. Lib
  9. Osgsimd. Lib
  10. Osgterraind. Lib
  11. Osgtextd. Lib
  12. Osgutild. Lib
  13. Osgviewerd. Lib

Step 5: write code

Print?

  1. # Include "stdafx. H"
  2. # Include <osgviewer/Viewer>
  3. # Include <OSG/node>
  4. # Include <OSG/geode>
  5. # Include <OSG \ group>
  6. # Include <osgdb/readfile>
  7. # Include <osgdb/writefile>
  8. # Include <osgutil \ optimizer>
  9. Int _ tmain (INT argc, _ tchar * argv [])
  10. {
  11. OSG: ref_ptr <osgviewer: viewer> viewer = new osgviewer: Viewer ();
  12. OSG: ref_ptr <OSG: group> root = new OSG: group ();
  13. OSG: ref_ptr <OSG: node> node = osgdb: readnodefile ("mymap. Earth ");
  14. Root-> addchild (node. Get ());
  15. Osgutil: optimizer;
  16. Optimizer. Optimize (root. Get ());
  17. Viewer-> setscenedata (root. Get ());
  18. Viewer-> realize ();
  19. Viewer-> Run ();
  20. Return 0;
  21. }

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:

  1. <Map Name = "mymap" type = "geocentric" version = "2">
  2. <Image name = "bluemarble" driver = "gdal">
  3. <URL> world. tif </URL>
  4. </Image>
  5. </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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.