Mogre Basic Tutorial 0         Setting up a Mogre Application

First notes

In the past this page was a help to setup Mogre.
Our new Mogre SDK installer will manage all you need to run Mogre.
To learn how Mogre works, just continue with the Mogre Basic Tutorial 1.
The obsolete content of this historical page was removed. Sections which are still useful are updated.

Building Your First Mogre Application

Creating a Project

As basis for your Visual Studio you can use a prepared VS project. Just look to page Mogre Wiki Tutorial Framework.

If you create a new VS project by scratch, be aware of this:

  • Set build target to x86 (even for use with 64 bit Windows) - Otherwise you will get a bad image format exception on x64 systems. (Reason: The precompiled binaries are build with x84 setting.) The build target you find in the project settings. (Right click to the project name in the file explorer)
  • Copy all binaries and *.cfg files from the MogreSDK to your binary directories (bin/debug and bin/release)
  • Perhaps you need to update the paths inside the *.cfg files (Use paths relative to your bin/release directory)
  • Add a reference to Mogre.dll. (Right click on "References" in the project, and select "Add Reference")
  • Add the line using Mogre; to all of your code files which handle with Mogre.

Adding Configuration Files

TODO: improve content of this section

Before we can actually use the project, we have to add three configuration files to our project. In windows, navigate to the C:\MogreSDK\bin\release directory and copy all files with the ".cfg" extention into your project's bin\debug, and bin\release folders (you may have to create the folders). Finally, open up the resources.cfg files you added to your project. You will notice it contains a relative path for the directories. We will have to set this manually to the absolute path. Replace all occurances of "../../" in the document with "C:/MogreSDK/".
You must do this for all relative directories, "including PluginFolder=." in Plugins.cfg.

Troubleshooting

Checklist

If you have problems getting started, check the following things first:

  • Did you install the Mogre SDK? If not, you could get trouble if a needed depency is missing. Look to page Mogre for the download links.
  • If you don't find the Mogre.dll files - Are you shure that you installed the Mogre SDK (.NET)? Perhaps you just installed the Ogre SDK, which is used for C++ only?
  • Did you set the target plattform from "Any CPU" to "x84"? This option you find in the project settings (right click to "Tutorial" in project overview Visual Studio). Then you choose the "Build" tabular of the project settings.
  • Did you add references to "Mogre.dll" in your project?
  • Did you copy the Ogre configuration files from the SDK directory to your project's output directories? (They should be placed in YourProjectsDirectory\bin\debug and YourProjectsDirectory\bin\release.)
  • Did you modify the config files in BOTH the release and debug directories to have the absolute path to the media files?
  • Did you update the drivers of your graphic card?
  • If you use Visual Studio 2010, perhaps you need to install the Microsoft Visual C++ 2008 SP1 Redistributable Package (x86). (In normal case this should be installed by the MogreSDK installer.)

Getting Help

If you have checked these things, feel free to post the problem you are having to the Mogre forums. Be sure to include a detailed description of the problem, the things you have tried to fix it, and paste the error messages from the Ogre.log file if there are any (this file is located in the project's output directory).

Exception Handling With Mogre

Before wrapping up this tutorial, I'd like to breifly mention how to handle exceptions which originate from Ogre itself. Mogre and C# can handle C++ exceptions, but they do not act as you would expect them to. If you ever see a message which states "Runtime Error! ... This application has requested the Runtime to terminate in an unusual way..." then you probably encountered an error in Ogre somewhere.

To properly handle an exception thrown by the C++ Ogre library, you need to catch an exception of the type System.Runtime.InteropServices.SEHException. After catching this exception, you can see if it's an Ogre exception (instead of just a crash) by checking the static OgreException.IsThrown property. If that property is true, then you handle the exception. For example, here is a chunk of code to catch and display an Ogre exception:

try
 {
     ...
 }
 catch (System.Runtime.InteropServices.SEHException)
 {
     if (OgreException.IsThrown)
         MessageBox.Show(OgreException.LastException.FullDescription,
                         "An Ogre exception has occurred!");
     else
         throw;
 }


Wrapping your main method with a try block such as this one can save you lots of headaches down the line when you are debugging your application. Notice we have not added a catch block to catch a generic Exception object. This way when we are debugging the application, Visual Studios can insert a breakpoint for an unhandled C# exception, whereas Visual Studios cannot do this for C++ exceptions.

Final Note

  • Depencies of the old Mogre version 1.6.4 are listed here.