2 October 2011

Setting up Ogre Project in Visual Studio 2010

Prerequisites - 

  • Visual Studio 2010 must be installed.
  • Ogre SDK 1.7 or greater must be installed. Use this link for installation details.
Steps to setup project - 


1. Set Environment variable - 
   Run setx OGRE_HOME path_to_ogre_sdk in a command console (cmd.exe).
   Alternatively create a batch file to set the variable. 
   Filename: OgreHome.bat
   Contents: setx OGRE_HOME %CD%
                  pause
   Location: Ogre Extracted folder ( Eg:-C:\OgreSDK_vc10_v1-7-3)

2. Create a new Visual Studio Project
   Make sure the windows application is selected and empty project is checked.
  

I kept the name as OgreProject.

2. Now download the sample ogre files to be included in the project - TutorialsFramework.zip.
   After downloading this zip file, extract the file into the project folder.
   Add those files to the project by selecting Add->Existing Item...

3. Change the project configuration.
   
Switch to All Configurations:

Under General Properties, set the Character Set to Multi-Byte Character Set


Under Debuggin Configuration Properties, set the following values:
Command : $(OGRE_HOME)\Bin\$(Configuration)\$(ProjectName).exe
Working Directory: $(OGRE_HOME)\Bin\$(Configuration)
   
  Now Goto Configuration Properties->C/C++->General->Additional Include Directories add following:
  $(OGRE_HOME)\include
$(OGRE_HOME)\include\OIS
$(OGRE_HOME)\include\OGRE 
$(OGRE_HOME)\Samples\Common\include
$(OGRE_HOME)\boost_1_44

In Configuration->Linker->General->Additional Library Directories add following - $(OGRE_HOME)\lib\$(Configuration)
$(OGRE_HOME)\boost_1_44\lib

In Configuration Properties->Build Events->Post Build Event->Command Line, add:
copy "$(OutDir)\$(TargetFileName)" "$(OGRE_HOME)\Bin\$(Configuration)"


Now make some Configuration Specific Settings. Switch Configuration to Active(Debug) : 

Add Input libaries for debug : 
OgreMain_d.lib
OIS_d.lib

Configuration Properties -> Linker -> Input ->Additional Dependencies -> Release
Switch configuration from Active(debug) to Active(release).
Add input libraries for release: 
OgreMain.lib
OIS.lib

4. Now Build your project and see the output. All executables generated are sent to the Ogre SDK's->Bin Folder as all the Ogre .dll files are there. So you may execute from there as well.

6 comments:

  1. Hey, great tutorial it worked perfectly.
    I was just wondering is there a way to have this set for every ogre project i create? or do i have to repeat the process every time?

    ReplyDelete
  2. There are ways to copy the project settings in visual studio. Easiest way is to copy the whole project and change its project name and the files within it. Another way is to copy the settings directly from the .vcxproj file from you project folder. This is an xml file which contains all the project settings. You can go through this for further details.

    ReplyDelete
  3. Since ogre needs a lot of resource files during runtime, its better to fix the output folder of each project to the same common directory. I would suggest to apply all these settings every time you create a new project, atleast in the beginning, before you become familiar with ogre.

    ReplyDelete
  4. Ok i will, thanks for the help

    ReplyDelete
  5. excuseme. can you help me.when i add the existing file,and built and it had some error.
    can not open "OgreCamera.h"
    can not open "OgreEntity.h"
    can not open "OgreLogManager.h"
    can not open "OgreRoot.h"
    can not open "OgreViewport.h"
    can not open "OgreSceneManager.h"
    can not open "OgreRenderWindow.h"
    can not open "OgreConfigFile.h"

    ReplyDelete
    Replies
    1. Mostly these files belong to generic ogre includes and $(OGRE_HOME)\Samples\Common\include... Check your include locations properly. That is the only situation when Visual Studio gives cannot open error for include files.

      Delete