OGRE Wiki
Support and community documentation for Ogre3D
Ogre Forums
ogre3d.org
Log in
Username:
Password:
CapsLock is on.
Remember me (for 1 year)
Log in
Home
Tutorials
Tutorials Home
Basic Tutorials
Intermediate Tutorials
Mad Marx Tutorials
In Depth Tutorials
Older Tutorials
External Tutorials
Cookbook
Cookbook Home
CodeBank
Snippets
Experiences
Ogre Articles
Libraries
Libraries Home
Alternative Languages
Assembling A Toolset
Development Tools
OGRE Libraries
List of Libraries
Tools
Tools Home
DCC Tools
DCC Tutorials
DCC Articles
DCC Resources
Assembling a production pipeline
Development
Development Home
Roadmap
Building Ogre
Installing the Ogre SDK
Setting Up An Application
Ogre Wiki Tutorial Framework
Frequently Asked Questions
Google Summer Of Code
Help Requested
Ogre Core Articles
Community
Community Home
Projects Using Ogre
Recommended Reading
Contractors
Wiki
Immediate Wiki Tasklist
Wiki Ideas
Wiki Guidelines
Article Writing Guidelines
Wiki Styles
Wiki Page Tracker
Ogre Wiki Help
Ogre Wiki Help Overview
Help - Basic Syntax
Help - Images
Help - Pages and Structures
Help - Wiki Plugins
Toolbox
Freetags
Categories
List Pages
Structures
Trackers
Statistics
Rankings
List Galleries
Ogre Lexicon
Comments
History: Setting Up An Application - Visual Studio
View page
Source of version: 141
(current)
{DIV(class="achtung")}__IMPORTANT:__ This guide is meant to be used with old releases of Ogre. For Ogre >= 1.10, rather use [https://ogrecave.github.io/ogre/api/latest/setup.html| a CMake based setup].{DIV} {DIV(class="Layout_box6")}{SPLIT(colsize=15%|85%)}{img fileId="1721"}--- {DIV(class="bigBold")}Setting Up An Application With Visual Studio{DIV}{SPLIT} {DIV} %clear% !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 [https://bitbucket.org/ogreaddons/ogreappwizards/downloads|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)). {maketoc} {VERSIONS(nav="y",default="Visual Studio 2010 - VC10")} Guide for setting up an Ogre application using Visual Studio 2010 (VC10). !!Prerequisites *Visual Studio 2010 must be installed. Express and higher. *The Ogre SDK version 1.7 or greater must be installed. **Installing the Ogre SDK: ((Installing the Ogre SDK)) **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. !Setting Up an Application for Visual Studio 2010 !!Environment Variables Run {MONO()}setx OGRE_HOME path_to_ogre_sdk{MONO} in a command console (cmd.exe): {img fileId="1655"} Alternatively, create this handy batch script: {CODE(wrap="1", colors="winbatch")} setx OGRE_HOME %CD% pause {CODE} Save it as {MONO()}OGRE_HOME.bat{MONO} and put it in the root directory of the Ogre SDK. Run it, and the OGRE_HOME environment variable points to that directory. Handy when you switch between several Ogre SDKs. !!New Project Create a new Win32 project ({MONO()}File -> New -> Project{MONO}): {img fileId="1656" width="400" thumb="y" alt="vc10step1.png" rel="box[g]"} Make sure that {MONO()}Windows Application{MONO} is selected and {MONO()}Empty Project{MONO} is checked: {img fileId="1658" width="400" thumb="y" alt="" rel="box"} !!Tutorial Framework Download the ((Ogre Wiki Tutorial Framework)). Extract Tutorial Framework: {img fileId="1659" width="400" thumb="y" alt="" rel="box"} Add Existing Items to Project: {img fileId="1660" width="400" thumb="y" alt="" rel="box"} Select Files: {img fileId="1661" width="400" thumb="y" alt="" rel="box"} !!Project Configuration Project Properties: {img fileId="1662"} --- !!!Common Settings Switching to All Configurations: {img fileId="1663" width="400" thumb="y" alt="" rel="box"} --- !!!!General Configuration Properties Set {MONO()}Character Set{MONO} to {MONO()}''Use Multi-Byte Character Set''{MONO} on the General Configuration Properties page: {img fileId="1665" width="400" thumb="y" alt="" rel="box"} --- !!!!Debugging Configuration Properties {MONO()}Command{MONO}: {CODE(wrap="1")} $(OGRE_HOME)\Bin\$(Configuration)\$(ProjectName).exe {CODE} {MONO()}Working Directory{MONO}: {CODE(wrap="1")} $(OGRE_HOME)\Bin\$(Configuration) {CODE} {img fileId="1664" width="400" thumb="y" alt="" rel="box"} --- !!!!Configuration Properties - C/C++ - General - Additional Include Directories {CODE(wrap="1")} $(OGRE_HOME)\include $(OGRE_HOME)\include\OIS $(OGRE_HOME)\include\OGRE $(OGRE_HOME)\Samples\Common\include $(OGRE_HOME)\boost {CODE} __Note:__ If you are using Ogre >1.9 also add "$(OGRE_HOME)\include\OGRE\Overlay" {img fileId="1667" width="400" thumb="y" alt="" rel="box"} --- !!!!Configuration Properties - Linker - General - Additional Library Directories {CODE(wrap="1")} $(OGRE_HOME)\lib\$(Configuration) $(OGRE_HOME)\boost\lib {CODE} {img fileId="1668" width="400" thumb="y" alt="" rel="box"} --- !!!!Configuration Properties - Build Events - Post-Build Event - Command Line {CODE(wrap="1")}copy "$(OutDir)\$(TargetFileName)" "$(OGRE_HOME)\Bin\$(Configuration)"{CODE} {img fileId="1669" width="400" thumb="y" alt="" rel="box"} --- !!!Configuration Specific Settings Switch configuration to "Active(Debug)". {img fileId="1670" width="400" thumb="y" alt="" rel="box"} --- !!!!Configuration Properties - Linker - Input - Additional Dependencies - Debug Add input libraries for debug: {CODE(wrap=1)} OgreMain_d.lib OIS_d.lib {CODE} __Note:__ If you are using Ogre >1.9, also add "OgreOverlay_d.lib". {img fileId="1671"} --- !!!!Configuration Properties - Linker - Input - Additional Dependencies - Release Switch configuration from "Active(Debug)" to "Active(Release)". Add input libraries for release: {CODE(wrap=1)} OgreMain.lib OIS.lib {CODE} __Note__: If you are using Ogre >1.9, also add " OgreOverlay.lib". {img fileId="1672" width="400" thumb="y" alt="" rel="box"} --- !!That's it! You've set up an Ogre project succesfully. All that remains is to build and run it. :) __Note:__ If you are running Ogre 1.9 and are getting a runtime error saying: "Cannot locate resource shadows.glsl in resource group Popular or any...", you have to edit "resources_d.cfg" and "resources.cfg" and add "FileSystem=../../media/materials/programs/GLSL" to the files. See this ((Basic Tutorial 1|#Missing_a_Configuration_File_or_DLLs|troubleshooting guide)) if you can not find the files. If you are getting errors like: "The program can't start because d3dx9_43.dll (or d3dcompiler_43.dll) is missing from your computer...." try to install the [http://www.microsoft.com/en-us/download/details.aspx?id=6812|DXSDK_Jun10.exe], if you want to use a DirectX renderer. If you only want to use the OpenGL-renderer, edit the "plugins_d.cfg" and "plugins.cfg" files, and edit out the lines Plugin=RenderSystem_Direct3D9_d Plugin=RenderSystem_Direct3D11_d (Put a # in front of them, or delete them!) {img fileId="1673" width="400" thumb="y" alt="" rel="box"} Make sure you optimize your build time with ((Precompiled headers)) !!ogre.cfg {CODE(wrap="1", colors="ini")}Render System=Direct3D9 Rendering Subsystem [Direct3D9 Rendering Subsystem] Allow NVPerfHUD=No FSAA=0 Floating-point mode=Fastest Full Screen=No Rendering Device=NVIDIA GeForce FX 5200 VSync=No Video Mode=800 x 600 @ 32-bit colour [OpenGL Rendering Subsystem] Colour Depth=32 Display Frequency=60 FSAA=0 Full Screen=Yes RTT Preferred Mode=FBO VSync=No Video Mode=1024 x 768{CODE} Note: If you hear your graphics card squealing when showing the Ogre head, turn Vsync to "yes" in ogre.cfg! Your graphics card will squeal when there are too many frames per second being rendered. ---(Visual Studio 2008 - VC9)--- !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: ((Installing the Ogre SDK)) **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 *Start Visual Studio 2008 *Create a new project: File | New | Project *Under project types select __Visual C++__ then under Templates select __Win32 Project__. *Navigate to the location in which your project will be located by clicking the __Browse__ button. It should __not__ be in either the SDK directory or in the source files for Ogre. + {img fileId="1640" rel="box[g]" width="400" thumb="y"} *Click the __OK__ button and the Win32 Application Wizard will be displayed. + {img fileId="1642" rel="box[g]" width="400" thumb="y"} *Click the __Next__ Button. *Select 'Windows Application' and 'Empty project' when prompted for the type of project to create. + {img fileId="1643" rel="box" width="400" thumb="y"} *Click the __Finish__ button. !!Creating the directory structure and adding files Download and extract the ((Ogre Wiki Tutorial Framework)) into your project directory and add them to the project. {img fileId="1644" rel="box" width="400"} *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="1648" rel="box" width="400" thumb="y"} {DIV(type="span")}{DIV} *Open each of the folders by clicking on the __+__ signs to the left of each folders name. + {img fileId="1649" rel="box" width="400" thumb="y"} *Right click on the each of the files and select __Include In Project__. + {img fileId="1650" rel="box" width="400" thumb="y"} *Select File|Save All from the Visual Studio menu. !!Setting up the environment *Right click on the project OgreTemplate and select properties. The following screen will be displayed. + {img fileId="1651" rel="box" width="400" thumb="y" thumb="y"} The Properties Pages are arranged in a hierarchy. By default, Visual Studio creates two configurations. The project is created with two configurations: __Debug__ and __Release__. You will notice in the upper left corner of the last screen shot that the "Debug" configuration is currently the active configuration. You can change which configuration is being shown by selecting the arrow in that drop-down box. There is an additional value in that drop-down box that indicates that you wish to change a property in all configurations called, surprisingly enough, __All Configurations__. This tutorial assumes that the operating system environment variable __OGRE_HOME__ has been set up to point to the SDK directory. *Select the __All Configurations__ Configuration by selecting the Configuration drop-down box and selecting "All configurations". Set the variables according to the following chart. You should click __Apply__ after each group of properties. + {CODE(wrap="1")} General | Output Directory : bin\$(ConfigurationName) General | Intermediate Directory : obj\$(ConfigurationName) General | Character Set : Use Multi-Byte Character Set Debugging | Command : bin\$(ConfigurationName)\$(ProjectName).exe Debugging | Working Directory : bin\$(ConfigurationName) Debugging | Environment : path=$(OGRE_HOME)\Bin\$(ConfigurationName) C/C++ | General | Additional Include Directories : include;$(OGRE_HOME)\include;$(OGRE_HOME)\include\OIS;$(OGRE_HOME)\include\OGRE;$(OGRE_HOME)\boost Linker | General | Additional Library Directories : $(OGRE_HOME)\lib\$(ConfigurationName);$(OGRE_HOME)\boost\lib {CODE} *Select the __Debug__ Configuration by selecting the Configuration drop-down box and selecting "Debug". Set the properties according to the following chart. + {CODE()} Linker | Input | Additional Dependencies : OgreMain_d.lib OIS_d.lib Linker | Debugging | Generate Debug Info : Yes (/DEBUG) {CODE} *Select the __Release__ Configuration by selecting the Configuration drop-down box and selecting "Release". Set the properties according to the following chart. + {CODE(wrap="1")} Linker | Input | Additional Dependencies : OgreMain.lib OIS.lib Linker | Debugging | Generate Debug Info : No {CODE} !!Building the project *Choose the __Debug__ Solution Configuration. *Right click on the project OgreTemplate and select __Build Project__. There should be no compile or link errors. ;: {img fileId="1652" rel="box[g]" width="400" thumb="y"} *Choose the __Release__ Solution Configuration. *Right click on the project OgreTemplate and select __Build Project__. There should be no compile or link errors. ;: {img fileId="1653" rel="box[g]" width="400" thumb="y"} Make sure you optimize your build time with ((Precompiled headers)) %%% !!Copying the config files from OGRE_HOME to the project As a final step we need to copy some additional files that will be needed to run this project. The build steps just performed created a folder in the project folder called __bin__ and underneath that folder two folders called __release__ and __debug__. Each of these folders acts as the working directory for their respective configurations when Ogre runs. The Ogre framework will be looking in the working directory for some configuration files and they will be slightly different depending on whether a debug or release version is being run. The configuration files that you will need to run each version are located in __$(OGRE_HOME)\bin\debug__ and __$(OGRE_HOME)\bin\release__. Copy the __*.cfg__ files from the OGRE_HOME directory to the corresponding project directory. !!Running the project *Run each version of the Project. If it all works correctly, you will the following screen: + {img fileId="1946" width="400" thumb="y" alt="" rel="box[g]"} * Select a rendering subsystem from the select box in the middle of the window and click 'Ok'. You should see the following: + {img fileId="1945" width="400" thumb="y" alt="" rel="box"} * If not, go back and verify that you entered all the project properties correctly. You are now ready to move on to the ((Tutorials|Basic Tutorials)). ---(Visual Studio 2005 - VC8)--- TBD ---(Visual Studio 2003 - VC7.1)--- TBD {VERSIONS} !Troubleshooting If you're still having problems building an application, then check ((Setting Up An Application)) to make sure your compiler is set up properly. You can also [http://www.ogre3d.org/phpBB2/search.php|search the forums]. It is likely that another user has already solved a similar problem. You can also look in the Ogre.log file in your 'dist/bin' directory for more detailed information about a failed build. This information can be very helpful when posting to the [http://www.ogre3d.org/forums/viewforum.php?f=2&sid=87b676ed9a450c1ba2b7d0c0eabadf1d|Help Forum]. __This troubleshooting will not be provided in later tutorials. Make sure you get things running smoothly before moving on.__ !!MessageBox Unicode Error If you are using Visual Studio with unicode support turned on, then you may encounter this error: {CODE(wrap="1", colors="c++")} error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char *' to 'LPCWSTR' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast {CODE} The problem is that the MessageBox function is expecting unicode input, and we are giving it an ANSI string. To fix this, find the following line: {CODE(wrap="1", colors="c++")} MessageBox(NULL, e.what(), "An exception has occurred!", MB_OK | MB_IConerror | MB_TASKMODAL); {CODE} And change it to this: {CODE(wrap="1", colors="c++")} MessageBoxA(NULL, e.what(), "An exception has occurred!", MB_OK | MB_IConerror | MB_TASKMODAL); {CODE} We are now calling MessageBoxA instead of MessageBox. The reason for this is that MessageBox is automatically either resolved to MessageBoxA (ANSI) or MessageBoxW (Wide/Unicode), depending on the project configuration. We fix the error by explicitly calling the ANSI function. !!Missing DLLs or Configuration Files If your application has missings DLLs or .cfg files, then you probably need to copy them over from the OgreSDK folder. In Visual Studio, when you build your application in release mode, it puts the release executable in the '\bin\release' folder and the debug executable in the '\bin\debug' folder. You must copy all of the DLL and .cfg files from the OgreSDK into the appropriate folders. You would copy the files from '[[OgreSDK]\bin\release' into '\bin\release' in your project. You will also need to edit the resources.cfg file to point to the correct paths. See the next section for more information on this. !!Problems With Resources Or Plugins First, make sure you have 'plugins.cfg' and 'resources.cfg' in the same directory as your exectuable. The 'plugins.cfg' file tells Ogre which rendering libraries are available (Direct3D9, OpenGL, etc.). The 'resources.cfg' file is used to specify the locations of textures, meshes, scripts, and other resources. Both are simple text files. Open them up and make sure they contain the correct paths. Otherwise, you might get errors that look something like this: {CODE(wrap="1", colors="c++")} Description: ../../Media/packs/OgreCore.zip - error whilst opening archive: Unable to read zip file {CODE} If this is the case, then open up 'resources.cfg' and correct the paths and make sure the resource actually exists. Note: You can't use environment variables such as ${OGRE_HOME} in these paths. !!IDE Won't Launch Application One reason this may be happening is that Ogre expects certain files to be in the same directory as the executable. If we do not set the working directory for our IDE to the location of these files, then it won't see that they exist because it expects them to be in the working directory. So we must make sure to get our working directory set up correctly. !!!Visual Studio The exact solution will vary based on which version of Visual Studio you are using, but the basic steps should be similar. Right click on your project in the solution explorer (not the solution itself), and go to the properties. Somewhere in the configuration properties should be options for "Debugging". Then look for a field called "Working Directory". This should be set to the location of your executable file. If you are having trouble figuring out what to put there, try to mimic the "Command" field, which should be in the debugging options. For example, in Visual C++ 2003, the "Command" field should be something like "..\..\bin\$(ConfigurationName)\$(TargetFileName)". For the Working Directory, we need to remove the TargetFileName part. In this case, the working directory would be "..\..\bin\$(ConfigurationName)". The exact string you have to put there ''may'' vary based on your version of Visual C++ and your build environment. Be sure to check what the Command field is before doing this. Make sure to change the Working Directory for both the Release and Debug configuration. In Visual C++ 2005 it will probably be something different entirely. I've found the "..\..\bin\$(ConfigurationName)" directory a good thing to try first, if it still does not work you may have to play with it some, or get help on the Ogre forums.
Search by Tags
Search Wiki by Freetags
Latest Changes
IDE Eclipse
FMOD SoundManager
HDRlib
Building Ogre V2 with CMake
Ogre 2.1 FAQ
Minimal Ogre Collision
Artifex Terra
OpenMB
Advanced Mogre Framework
MogreSocks
...more
Search
Find
Advanced
Search Help
Online Users
127 online users