History: Setting Up An Application - Visual Studio
Source of version: 12
- «
- »
Copy to clipboard
{maketoc}
!Introduction
This set of instructions will walk you through setting up a Visual Studio C++ project from scratch. An alternative to this tutorial is to use the [http://code.google.com/p/ogreappwizards/|Ogre Application Wizard] instead. This tutorial is still useful if you wish to understand what the Application Wizard does for you. When you have finished this tutorial you will be able to compile a working Ogre Application and you will be ready to start the ((Basic Tutorials)).
!Prerequisites
*Visual Studio 2008 must be installed. [http://www.microsoft.com/express/Downloads/#2008-Visual-CPP|Visual Studio Downloads]
*The Ogre SDK version 1.7 or greater must be installed.
**Installing the Ogre SDK: __No SDK install yet__
**Build Ogre from source with CMake: ((CMake Quick Start Guide) If you are building Ogre from source, you must build the debug and release targets and execute the Install script for both targets as well. This will create a directory structure that is identical to the binary install structure.
!Tutorial
!!Creating a new project
*Create a new project: File | New | Project
*Under project types 'Visual C++' then under Templates select 'Win32 Project'.
*Enter a name for your project. Change the location to point to a work directory. It should __not__ be in either the SDK directory or in the source files for Ogre.
{REMARKSBOX(type="tip",highlight="y")}I suggest naming your project "OgreTemplate" so that its' purpose is obvious. You can use a copy of this project's files once you have finished this tutorial thus avoiding repeating this long process.{REMARKSBOX}
{img fileId="1640" rel="box[g]"}
*Click the OK button and the Win32 Application Wizard will be displayed.
{img fileId="1642" rel="box[g]"}
*Press the Next Button.
*Select 'Windows Application' and 'Empty project' when prompted for the type of project to create.
{img fileId="1643" rel="box[g]"}
*Click the Finish button.
At this point, some of the steps become less intuitive. Good organization dictates that we at least keep our header (.h) files separate from our source(.cpp) files. There are several ways to create sub-directories under our project directory. I will stick to doing everything in Visual Studio. The Solution Explorer window should be displayed, probably docked on the left side of the Visual Studio Window. If it is not visible, select the menu View | Solution Explorer.
{img fileId="1644" rel="box[g]"}
*If you hover over the second button in the Solution Explorer's toolbar, you will see that it says "Show all files" It should not currently be toggled so you should click on it to toggle it. Now you will see this display of Solution Explorer.
{img fileId="1645" rel="box[g]"}
*Select the menu Project | New Folder and type "source" in the editable area that is displayed in the Solution Explorer. This will create a sub-directory under the project directory called "source".
*Click on the project OgreTemplate in the Solution Explorer window. This will ensure that the next sub-directory gets created under the project directory and not under the source directory you just created. Select the menu Project | New Folder and type "include" in the editable area that is displayed in the Solution Explorer. This will create a sub-directory under the project directory called "include".
*Again, click on the project OgreTemplate in the Solution Explorer window. Select the menu Project | New Folder and type "scripts" in the editable area that is displayed in the Solution Explorer. This will create a sub-directory under the project directory called "scripts".
{img fileId="1646" rel="box[g]"}
*Create a new source file by selecting 'Project -> Add New Item...'. Make sure the file is in the work directory. This step __must__ be performed before editing project properties (otherwise the 'C/C++' page will be unavailable).
Save the project.
If you named your project "Testproject" and selected a location like C:\Work, and checked the box called "Create directory for solution", with a solution name of "Testsolution", then the directory structure will be: C:\Work\Testsolution\Testproject. If you do not create a directory for the solution, the structure will simply be: C:\Work\Testproject.
To clarify where the DLL files should be, an easy way is to copy the \bin folder (containing \debug and \release) and the \media folder from the OGRE installation directory to your Testproject folder (note: in this case you might be copying DLLs that won't be needed, but it's the hassle-free way). If you follow the convention presented above and you created folders for the header, scripts and source files, you have the following folders under \Testproject (excluding subfolders): 'bin', 'include', 'media', 'testsolution', 'scripts', and 'src'. However, if you don't want to copy them while running your Testproject from Visual Studio just add the path to OGRE's DLL files to the %PATH% global environment variable like this:
{CODE(wrap="1")}
Debugging : Environment = PATH=%PATH%;%OGRE_HOME%\bin\debug
{CODE}
and for the release version
{CODE(wrap="1")}
Debugging : Environment = PATH=%PATH%;%OGRE_HOME%\bin\release
{CODE}
This will __not__ modify the %PATH% environment variable permanently, just for the given run, so its safer. You could modify it globally for all windows applications like this:
{CODE(wrap="1")} My Computer -> Properties -> Advanced -> Environment Variables -> System Variables -> Path += ;%OGRE_HOME%\bin\debug
{CODE}
or
{CODE(wrap="1")} My Computer -> Properties -> Advanced -> Environment Variables -> System Variables -> Path += ;%OGRE_HOME%\bin\release
{CODE}
but this could lead to confusion if working with different Ogre versions and is __not__ recommended.
If you follow the next few steps carefully, your project should compile without errors.
Configure your project with the following settings. All of these are for the Debug configuration. To set up the Release configuration just change the directories from '\Debug\' to '\Release\'. Select "project properties" and under "configuration properties" add the following:
{CODE(wrap="1")} Debugging : Command = $(OutDir)\$(ProjectName).exe
Debugging : Working Directory = $(OutDir)
C/C++ : Preprocessor : Preprocessor Definitions += _STLP_DEBUG (only in Debug mode, not needed for .Net 2003 and 2005)
C/C++ : Code Generation : Use runtime library = Multithreaded Debug DLL (Multithreaded DLL in Release)
Linker : General : Output File = ..\bin\Debug\[appname].exe
Linker : Input : Additional Dependencies += OgreMain_d.lib OIS_d.lib (OgreMain.lib OIS.lib in Release)
{CODE}
If you also use CEGUI, you need to tell Visual Studio to link the libs by doing this:
{CODE(wrap="1")} Linker : Input : Additional Dependencies += CEGUIBase_d.lib OgreGUIRenderer_d.lib (CEGUIBase.lib OgreGUIRenderer.lib in Release)
{CODE}
And, for those using the SDK:
{CODE(wrap="1")} C/C++ : General : Additional Include Directories = ..\include;$(OGRE_HOME)\include;$(OGRE_HOME)\samples\include
Linker : General : Additional Library Directories = $(OGRE_HOME)\lib{CODE}
Or, for those using the source release:
{CODE(wrap="1")} C/C++ : General : Additional Include Directories = ..\include;$(OGRE_SRC)\OgreMain\include;$(OGRE_SRC)\Samples\Common\Include
Linker : General : Additional Library Directories = $(OGRE_SRC)\OgreMain\Lib\Debug
{CODE}
Additional hints on getting your application to run from within the IDE:<br \>
((Visual Studio Debugging Settings))