Tuesday, November 10, 2009

Installing OpenSceneGraph 2.8.0

I have gotten help with installing OpenSceneGraph on Windows XP. It was simple after all, at least using the pre-compiled binaries. I just wanted to get started making apps using OSG. With some helpful advice from the OSG community, here’s my detailed instructions for installing OSG on Windows XP from the pre-compiled binaries for use with Visual Studio 2005. The instructions are similar for other versions of Windows and Visual Studio, but I have no experience with them with regard to OSG. This tutorial assumes some experience (but not much) with C++, Visual Studio, command line usage, and Windows XP.

  1. First, you have to actually get the binaries. They can be found here.
  2. Download the packages labeled (i) "openscenegraph-all-2.8.0-win32-x86-vc80sp1-Debug.tar.gz" and (ii) "openscenegraph-all-2.8.0-win32-x86-vc80sp1-Release.tar.gz". They are the files associated with the Debug and Release builds, respectively.
  3. Also download the Sample Datasets labeled OpenSceneGraph-Data-2.8.0.zip (found here).
  4. Uncompress all three archives (try 7-zip for the .tar.gz files). Put all the directories from the Debug release in a directory you want to be the install directory. I’m going to assume C:\Program Files\OpenSceneGraph-2.8.0 from now on as the root for your installation.
  5. Inside the root, you should now see that it contains the folders: bin, doc, include, lib, and share
  6. So you can use both the debug and release builds of each library, go to the Release version’s folder (uncompressed) and copy all the contents into your installation directory. If and when it asks to overwrite a file, click no to all.
  7. It doesn’t really matter where you put the Sample files, so I made a folder in my installation directory called “samples” and copied them there (specifically “C:\Program Files\OpenSceneGraph-2.8.0\samples\OpenSceneGraph-Data-2.8.0″). These files are useful for running examples and giving access to basic fonts and textures.
  8. Now the files are “installed”, but Windows doesn’t know how to use them. To do that, we have to modify the environmental variables.
    1. Right-click on My Computer and select Properties.
    2. Select the Advanced tab.
    3. Click the Environmental Variables button.
    4. Under “System Variables” select the New button.
    5. Give the variable name “OSG_ROOT”.
    6. Give the variable value “C:\Program Files\OpenSceneGraph-2.8.0″ or whereever your install directory is.
    7. Now do the same for several other references, which refer to the OSG_ROOT variable:
      • Name: OSG_BIN_PATH | Value: %OSG_ROOT%\bin
      • Name: OSG_INCLUDE_PATH | Value: %OSG_ROOT%\include
      • Name: OSG_LIB_PATH | Value: %OSG_ROOT%\lib
      • Name: OSG_SAMPLES_PATH | Value: %OSG_ROOT%\share\OpenSceneGraph\bin
      • Name: OSG_FILE_PATH | Value: %OSG_ROOT%\samples\OpenSceneGraph-Data-2.8.0 (note: your directory structure may be different, see above)
    8. Then, select the already existing Path variable, and click Edit.
    9. To the end of the line, after the final semi-colon, add “%OSG_BIN_PATH%;%OSG_SAMPLES_PATH%;”
    10. Apply your changes and close the windows
    11. Your environmental variables should be successfully changed.
    12. To make sure they are working, open a command line window by going to Start, then Run, type “cmd”, and push OK.
    13. Type in “echo %OSG_ROOT%” and hit enter. It should display your install directory.
  9. At this point, you can also test to make sure Windows understands where OSG is. Open a command line window and type “osgversion”. It should return the version of OSG, namely “OpenSceneGraph Library 2.8.0″.
  10. Furthermore, you can test that the sample datasets have been installed by typing “osgviewer cow.osg” into the command line window. This should open the cow model in OSG’s viewer program. Push the escape key to exit.
  11. Now, we need to set up Visual Studio.
    1. Open Visual Studio 2005. If it was already open, close it and reopen it (so that it will get the latest changes you just made above).
    2. Select File > New > Project… and choose Empty Project under Visual C++ > General.
    3. Put it in a directory you’ll remember, and name is something like “OSGDefaultProject”.
    4. So that you will have all the necessary available options, create a new C++ file that will serve as your main file. (I named mine “Main.cpp”.)
    5. Select Project > [ProjectName] Properties…
    6. Select the Debug option from the Configuration dropdown.
    7. Select Configuration Properties > C/C++ > General
    8. Select the box to the right of Additional Include Directories and paste “$(OSG_INCLUDE_PATH)” there.
    9. Select Configuration Properties > C/C++ > Preprocessor
    10. Select the box to the right of Preprocessor Definitions and paste “WIN32;_WIN32;_DEBUG”
    11. Select Configuration Properties > Linker > General
    12. Select the box to the right of Additional Library Directories and paste “$(OSG_LIB_PATH)”
    13. Select Configuration Properties > Linker > Input
    14. Select the box to the right of Additional Dependencies and paste whatever libraries you will use. For now, paste these: osgd.lib osgGAd.lib osgDBd.lib osgViewerd.lib osgTextd.lib osgUtild.lib OpenThreadsd.lib
    15. Now the Debug mode is set up. Select the Release configuration and follow the same steps, except that the library names should NOT have a ‘d’ at the end (As.osg.lib osgGA.lib osgDB.lib osgViewer.lib osgText.lib osgUtil.lib OpenThreads.lib), and in the Preprocessor Definitions change “_DEBUG” to “NDEBUG”.
    16. Visual Studio should now be set up.
  12. Finally, you need to test it.
    • Into your C++ file, you need to copy some valid OSG code.
    • Many test their installation with osgViewer.cpp which can be found in OSG’s source.
    • If you don’t have the source or want a quicker method, go to this tutorial and download "BasicGeometry.cpp" placed at the bottom of that page.
    • There are links at the bottom to the full source for the tutorial. Copy the text into your file.
    • Compile and run. You should see two colored pyramids that you can rotate with your mouse.
  13. Now that it’s installed and you have a working project, you can use this project as a basis for all your OSG projects.

And that’s it. Hopefully the tutorial wasn’t too simplistic. This is the quickest way I know how to install it on Windows. If you want to install from source, try some of the links below.

1 comment:

Anonymous said...

Looked like this:
http://dwightdesign.com/2009/05/installing-openscenegraph-280/