OGRE (Object-Oriented Graphics Rendering Engine)

Creating project files for OGRE

Files

In these tutorials I will assume that the projects being created are located in their own folder in OgreNew\Samples. I will use APPNAME as a place holder for where you type in the name of the application. So in the example of where the project files should be stored it would be OgreNew\Samples\APPNAME.

NB: In a moments time we will embark on creating a small application called "Space", based on some of the examples supplied with Ogre. I suggest that if you plan on doing that tutorial that you use Space as the APPNAME.

Visual C++ 7

The first thing you need to do is create a blank Win32 Project. Make sure that you create a C++ project and that you have ticked the "Empty Project" tick box.
Now right click on the project in the solution explorer and change the following properties:

    Debug - Working Directory=..\Common\Bin\DebugC/C++ - Preprocessor Defines=_WINDOWS,_STLP_USE_DYNAMIC_LIB,OGRE_LIBRARY_IMPORTS,_DEBUG,WIN32,_STLP_DEBUG
    C/C++ - Additional Include Directories=..\Common\Include ..\..\OgreMain\include
    Linker - Output File=..\Common\Bin\Debug\APPNAME.EXELinker - Additional Library Directories=..\..\OgreMain\Lib\DebugLinker - Additional Dependencies=OGREMain.LIB

NB: Check that your application is set to use the 'Multithreaded [Debug] Dll' runtime library (under the code generation options in the C++ section).

In release mode you should change 'Debug' to 'Release', and remove the preprocessor defines '_DEBUG' and '_STLP_DEBUG'.

Copy Samples\Skyplane\Src\SkyPlane.CPP and Samples\Skyplane\Include\SkyPlane.H into the directory with your project. Right click on the project in the solution explorer and select "Add Existing Item". Highlight the two files you just copied and then rebuild your solution. Now run it in debug mode. Everything should work.

Now remove those two files from your project and delete them from your projects directory.

The last step that we need to take in setting up the project is to create the main program loop. This is simpler than it sounds because if we are following the Ogre Example Framework then all it means we do is create an instance of our Application object and call it's go() method. In Visual C++ it will look like this:

    /* APPNAME.CPP */

    #include "Ogre.h"
    #include "APPNAMEApplication.h"

    #define WIN32_LEAN_AND_MEAN
    #include "windows.h"

    INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
    {
        // Create application object
        APPNAMEApplication app;

        try {
            app.go();
        } catch( Ogre::Exception& e ) {
            MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL );
        }

        return 0;
    }

This doesn't compile does it? No, because we have not written APPNAMEApplication.h yet. That will be discussed in the next section.

Visual C++ 6

This is almost identical to the instructions for Visual C++ 7.

The first thing you need to do is create a blank Win32 Project. Make sure that you create a C++ project and that you have ticked the "Empty Project" tick box.
Now select "Project" from the menu and then select "Settings". We'll change some properties from here (legend is T=Tab, C="Category"):

    		(T) Debug - (C) General - Working Directory
    		=
    		..\Common\Bin\Debug

    		(T) C/C++ - (C) Preprocessor - Preprocessor Definitions
    		=
    		_WINDOWS,_STLP_USE_DYNAMIC_LIB,OGRE_LIBRARY_IMPORTS,_DEBUG,WIN32,_STLP_DEBUG

    		(T) C/C++ - (C) Preprocessor - Additional Include Directories
    		=
    		..\Common\Include,..\..\OgreMain\include

    		(T) Link - (C) General - Output Filename
    		=
    		..\Common\Bin\Debug\APPNAME.EXE

    		(T) Link - (C) Input - Additional Library Path
    		=
    		..\..\OgreMain\Lib\Debug

    		(T) Link - (C) General - Object/Library Modules
    		=
    		OGREMain.LIB (add to whatever is there)

NB: Check that your application is set to use the 'Multithreaded [Debug] Dll' runtime library (under the code generation options in the C++ section).

In release mode you should change 'Debug' to 'Release', and remove the preprocessor defines '_DEBUG' and '_STLP_DEBUG'.

Copy Samples\Skyplane\Src\SkyPlane.CPP and Samples\Skyplane\Include\SkyPlane.H into the directory with your project. Select "Project" from the menu then select "Add To Project" and finally "Files...". Highlight the two files you just copied, click OK and rebuild your solution. Now run it in debug mode. Everything should work.

Now remove those two files from your project and delete them from your projects directory.

The last step that we need to take in setting up the project is to create the main program loop. This is simpler than it sounds because if we are following the Ogre Example Framework then all it means we do is create an instance of our Application object and call it's go() method. In Visual C++ it will look like this:

    /* APPNAME.CPP */

    #include "Ogre.h"
    #include "APPNAMEApplication.h"

    #define WIN32_LEAN_AND_MEAN
    #include "windows.h"

    INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
    {
        // Create application object
        APPNAMEApplication app;

        try {
            app.go();
        } catch( Ogre::Exception& e ) {
            MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL );
        }

        return 0;
    }

This doesn't compile does it? No, because we have not written APPNAMEApplication.h yet. That will be discussed in the next section.

Linux

Under construction.

Borland

Under construction.

Mac OSX

The first thing you need to do is to download a sample Makefile to build your app. Put this in the Ogrenew/Samples/Space directory. Copy Samples/Skyplane/Src/SkyPlane.CPP and Samples/Skyplane/Include/SkyPlane.H into this same directory (ie. there should now be 3 files in this directory).

Let's take a look at portions of the Makefile that you would need to amend:

    # TOPDIR points to the main directory where you installed Ogre
       TOPDIR = /source/ogrenew

Amend this path to reflect the path of your Ogre installation

    # DEVIL_LIBS points to src path for DevIL
       DEVIL_LIBS =  -L/source/DevIL/src-Il/src

Amend this path to reflect the path to the DevIL 'src' directory.

In the Terminal, 'cd' into Ogrenew/Samples/Space and do a 'make'. To run this built application, 'cd' into Ogrenew/Samples/Common/bin and do a './mySkyPlane'. Everything should work.

Now remove those two files (.cpp & .h) from your directory.

You will now need to edit the Makefile to reflect your new source files as follows

    # SRCFILES points to all files to be compiled
       SRCFILES = APPNAMEApplication.cpp

Amend the source file name to the name of your new .cpp file

    # APPNAME is the filename of the generated executable
       APPNAME = $(TOPDIR)/Samples/Common/bin/APPNAMEApplication

Edit this to reflect the location and name of your executable. For this project, place it in the Ogrenew/Samples/Common/bin directory for simipliity.

    # INCLUDES points to additional include directories
       INCLUDES = -I. -I$(TOPDIR)/Samples/APPNAME/include  ...

If you are storing you .h file in a 'include' subdirectory, add its path here so that it could be located

The last step that we need to take in setting up the project is to create the main program loop. This is simpler than it sounds because if we are following the Ogre Example Framework then all it means we do is create an instance of our Application object and call it's go() method. In Visual C++ it will look like this:

    /* APPNAME.CPP */
    #include "Ogre.h" #include "APPNAMEApplication.h"

    #if OGRE_PLATFORM == PLATFORM_WIN32
    #define WIN32_LEAN_AND_MEAN
    #include "windows.h"
    INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
    #else
    int main(int argc, char *argv[])
    #endif
    {
       // Create application object
       APPNAMEApplication  app;
       try {
          app.go();
       } catch( Ogre::Exception& e ) {

    #if OGRE_PLATFORM == PLATFORM_WIN32
       MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!",    MB_OK | MB_ICONERROR | MB_TASKMODAL );
    #else
       std::cerr << "An exception has occured: " <<
       	e.getFullDescription().c_str() << std::endl;
    #endif
       }

       return 0;
    }

Note that this source differs from the one provided. It includes codes for platforms other than Windows. The source for the .cpp file remains unchanged. Now run 'make' agin in the Terminal. This doesn't compile does it? No, because we have not written APPNAMEApplication.h yet. That will be discussed in the next section.

Back to Index |  | << Previous section | Next section >>