|Version 5 (modified by martin, 9 years ago)|
- Developer Blog
- Mailing Lists
- Getting Started
- Platform Specifics
- User Guides
- Programming Guides
- Reference Guides
- Tips And Tricks
- Knowledge Base
- Trac Usage Examples
- TracGuide Documentation
- Software Patents
- Software Patents Europe
Follows are details on usage of OpenSceneGraph such as how to get things compiling using Microsoft Visual Studio .NET and Visual Studio 6.0.
Compiling with Visual Studio .NET
(Note: These instructions are valid for Visual Studio .NET 2005 (8.0) and Visual Studio Express 2005 (see below), but they should also apply to Visual Studio .NET 2003 (7.0). -- Jean-Sebastien Guay)
The project files are set up so that if you have the dependencies in the same base directory as the OpenSceneGraph sources, then it will find them. Thus, the suggested directory structure is:
OpenSceneGraph-VERSION (replace VERSION by 1.2 or SVN or whatever)
OpenSceneGraph-VERSION\3rdParty (put the contents of the 3rdParty zip file in here)
Note: for the 3rdParty directory, see Dependencies and download the "3rdParty_Win32binaries" zip file. Unzip it so that the bin, lib etc. directories are directly under OpenSceneGraph-VERSION\3rdParty .
Once that is set up, you can compile it.
Now that a) OpenThreads is included in the OpenSceneGraph source tree and b) Producer is no longer a prerequisite dependency, compiling OSG is simpler than ever. However, you need CMake to generate Solution and Project files. Download it at http://www.cmake.org/HTML/Download.html .
Start the CMake GUI once it's installed, and open the CMakeLists.txt from the root OpenSceneGraph directory in the "Where is the source code" field. The same directory will be automatically put into the "Where to build the binaries" field. I like to do out-of-source builds, so I generally add \build to the end. Then click Configure.
You can then customize your build. Some variables will be filled in automatically (such as ACTUAL_3RDPARTY_DIR, if you followed the directory structure above). I typically enable BUILD_OSG_EXAMPLES and set CMAKE_INSTALL_PREFIX to the OpenSceneGraph directory so that the binaries are installed in OpenSceneGraph\bin. You can also set it to somewhere else if you want to keep your source tree clean. Check if the dependencies you have are detected - if not put in the paths manually. Any plugins or examples for which you don't have the dependencies will just not be part of the generated project files, which is cleaner than it was before (the projects would be there but just refuse to build, which resulted in lots of noise when building for things you knew would not build anyway).
Once your build configuration is to your liking, click Configure one last time and then click Generate. Then, open the generated OpenSceneGraph.sln file, which will be in OpenSceneGraph\build, with Visual Studio. Select your desired build type (Debug, Release, RelWithDebugInfo?, MinSizeRel?) and press F7 for "Build Solution". Assuming everything builds correctly, you can then right-click on the INSTALL project and build that, which will copy the compiled files to the correct directories (based on what you set CMAKE_INSTALL_PREFIX to). Before that, the compiled files all reside in the build directory, and I don't recommend you use them from there.
A word of warning, the first time you compile from source it will take some time. After that, if you update an SVN checkout for example, it will compile incrementally (only what changed) so that's quite a bit faster.
Note also that you should regenerate the project files with CMake each time you update from SVN or update to a newer snapshot of the source code. That will make sure that a) any new build configuration options added to the CMake build files will be taken into account, and b) any new files will be included in the VS projects and compiled correctly. You can regenerate the build files by just opening the root CMakeLists.txt in the CMake GUI and setting the build directory to the same thing you had before (OpenSceneGraph\build, for example), that way any settings you had made will still be there. Just click Configure then Generate, open the OpenSceneGraph.sln and build.
Finally, note that from time to time, to see new settings, you will need to delete the CMakeCache.txt file in the build directory, which will also erase your settings... This should be rare though.
Using Visual Studio Express 2005
Visual Studio Express is a free Microsoft development system, a complete Visual Studio based on Visual Studio .NET 2005, with all the features of VS 6 (debugger, icon designer, MS interface developer) . The download is free but 336MB; the license is perpetual but MS reserve the right to charge after Nov 2006. You can also download C#, J# and other studio components. You will also need the Platform SDK to provide links and some needed libraries.
Please follow the instructions at this page to download the Platform SDK (which is included with commercial versions but a separate download for the Express version). Also, it appears that some features of VS, such as ability to produce a Console application, are hidden until you modify the configuration files (instructions also at the previous link, at the bottom of the page).
See the instructions for Visual Studio .NET above to compile OpenSceneGraph with Visual Studio Express 2005.
All in all it works as well as the commercial version (Visual Studio .NET 2005).
Note that the Express Edition does not include MFC, so any example written for MFC will fail to build (currently, osgviewerMFC).
Compiling with Visual Studio 6.0
With the advent of Visual Studio Express 2005 (see above), going through all the hoops required to get OpenSceneGraph to compile on Visual Studio 6.0 seems a lot less appealing. It's probably a lot easier to just install VS Express and the Platform SDK and use those. You get a free, up-to-date compiler and development environment in which you can work, and you don't need to worry about VS 6's issues. Nonetheless, instructions to get OpenSceneGraph to compile in Visual Studio 6.0 follow.
VS 6 has poor support for STL templates. You must obtain STLport http://www.stlport.org/download.html or equivalent (such as dinkumware's replacement at http://www.dinkumware.com/ which I have not tested).
Please use STLport-4.5, since earlierer and newer versions cause more or less problems!!!
You only need the header files supplied with stlport - no need to compile or edit the code installed, with the following exception:
Edit stlport/stl_user_config.h at about line 45 (your's may vary) and comment _IN_ (should be commented _OUT_ by default)
# define _STLP_NO_OWN_IOSTREAMS 1
Set the include file paths (under tools Options..., subtab Directories) to include the stlport include directory, and raise this directory up the list of include search paths (or else MS's old and non-useful stl will be used first). This is a good opportunity to add the Openthreads & Producer include file paths as well since they will be used by many projects.
The Directories tab can also be used to set search path for libraries - set these to include Producer & Openthreads.
Building OpenSceneGraph 1.2
The .dsp files included with the 1.2 versions of OpenSceneGraph, Producer, and OpenThreads have some settings that are not compatible with VS 6, in order to enable 64 bit builds in VS 8. These settings must be changed, prior to building with VS 6, by replacing all instances of:
- $(PlatformName) with win32, and
- $(ConfigurationName) with Debug or Release as appropriate.
A Perl script is in OpenSceneGraph/VisualStudio/fixup-vc6-dsps.pl to perform these changes automatically. Run it using either Windows or Cygwin Perl.
A new project
I usually insert a new project into the main OSG workspace because:
- it may depend on a feature of another dll; then the dependency check in VS 6 will then recompile the dll if I have made a change to that code.
- I can switch rapidly from the current project to a piece of test code for an item in a dll
- I can examine code for any src/example easily.
(You could alternatively create a smaller workspace file with just the dlls that you are modifying plus the project(s) currently in development).
Extensionless headers and syntax highlighting on Visual Studio 6
The OpenSceneGraph uses Standard C++ style extensionless headers, which poor Visual Studio doesn't automatically recognize as suitable for syntax highlighting (compile works fine though), even the Standard C++ header themselves require a hack to get Visual Studio to highlight them properly. The easy answer is to use that same hack to get it to recognize the OpenSceneGraph headers too. To make easy a modified header listing file can be found in the VisualStudio?/LANDEXT.DAT. First copy the original LANDEXT.DAT file (located in C:\Progam Files\Microsoft Visual Studio\Common\MSDev98\Bin) to LANDEXT.DAT.BKP, and then copy over the OpenSceneGraph one. Once you have done this Visual Studio will syntax highlight them without problem.
Extensionless headers and syntax highlighting on Visual Studio 7 or 8
You will find two registry files at :
and a MUST_READ_ME.txt file. Double clicking on the appropriate .reg file will add syntax highlighting for extensionless header files.
I didn't find out where this is stored in the registry, but to enable C++ highlighting to OSG's extensionless headers, go to Tools-Options, then Text Editor-File Extension, check "Map Extensionless Files To" at the bottom and select "Microsoft Visual C++" in the list to the right. -- Jean-Sebastien Guay