Book Image

OGRE 3D 1.7 Beginner's Guide

Book Image

OGRE 3D 1.7 Beginner's Guide

Overview of this book

Want to make your own 3D applications, simulations, and games? OGRE 3D, an open source Object-Oriented 3D Graphics Rendering Engine written in C++, which can be utilized to create a variety of 3D applications and is commonly used in game creation, can help you to do so! OGRE 3D 1.7 Beginner's Guide, based on the latest version 1.7, makes it super easy for you to make your own monsters, spaceship shooters, weapons, enemies, and more!OGRE 3D 1.7 Beginner's Guide will teach you to develop 3D applications that are exciting and interesting and if used correctly can result in stunning games and simulations. You will start from the very beginning and then work your way up to complex scenes and stunning effects.In this book you will start with how to download and configure OGRE 3D, then create your first example scene. With the help of this sample scene, you will be introduced to several related topics each of which will be explained through several other examples and by do-it-yourself tasks. After each example there is a section that explains the theory behind the technique used for deeper understanding. You will also use what you learned in one example in another example and repeat each technique several times while learning new ones at the same time to strengthen the topics learned. Within no time you will master the art of game creation. Imagine how great you will feel when all your friends are playing the great-looking games you've created with OGRE 3D and this book.
Table of Contents (17 chapters)
Ogre 3D 1.7
Credits
About the Author
About the Reviewers
Preface
Index

Time for action — starting the project and configuring the IDE


As with any other library, we need to configure our IDE before we can use it with Ogre 3D.

  1. Create a new empty project.

  2. Create a new file for the code and name it main.cpp.

  3. Add the main function:

    int main (void)
    {
    return 0;
    }
    
  4. Include ExampleApplication.h at the top of the following source file:

    #include "Ogre\ExampleApplication.h":
    
  5. Add PathToYourOgreSDK\include\ to the include path of your project.

  6. Add PathToYourOgreSDK\boost_1_42 to the include path of your project.

  7. Add PathToYourOgreSDK\boost_1_42\lib to your library path.

  8. Add a new class to the main.cpp.

    class Example1 : public ExampleApplication
    {
    public:
    void createScene()
    {
    }
    };
    
  9. Add the following code at the top of your main function:

    Example1 app;
    app.go();
    
  10. Add PathToYourOgreSDK\lib\debug to your library path.

  11. Add OgreMain_d.lib to your linked libraries.

  12. Add OIS_d.lib to your linked libraries.

  13. Compile the project.

  14. Set your application working directory to PathToYourOgreSDK\bin\debug.

  15. Start the application. You should see the Ogre 3D Setup dialog.

  16. Press OK and start the application. You will see a black window. Press Escape to exit the application.

What just happened?

We created our first Ogre 3D application. To compile, we needed to set different include and library paths so the compiler could find Ogre 3D.

In steps 5 and 6, we added two include paths to our build environment. The first path was to the Ogre 3D SDK include folder, which holds all the header files of Ogre 3D and OIS. OIS stands for Object Oriented Input System and is the input library that ExampleApplication uses to process user input. OIS isn't part of Ogre 3D; it's a standalone project and has a different development team behind it. It just comes with Ogre 3D because the ExampleApplication uses it and so the user doesn't need to download the dependency on its own. ExampleApplication.h is also in this include folder. Because Ogre 3D offers threading support, we needed to add the boost folder to our include paths. Otherwise, we can't build any application using Ogre 3D. If needed, Ogre 3D can be built from the source, disabling threading support and thus removing the need for boost. And while using boost, the compiler also needs to be able to link the boost libraries. Thus we have added the boost library folder into our library paths (see step 7).

In step 10, we added PathToYourOgreSDK\lib\debug to our library path. As said before, Ogre 3D comes with debug and release libraries. With this line we decided to use the debug libraries because they offer better debug support if something happens to go wrong. When we want to use the release versions, we have to change the lib\debug to \lib\release. The same is true for steps 11 und 12. There we added OgreMain_d.lib and OIS_d.lib to our linked libraries. When we want to use the release version, we need to add OgreMain.lib and OIS.lib. OgreMain.lib, and OgreMain_d.lib contains both the interface information about Ogre 3D and tells our application to load OgreMain.dll or OgreMain_d.dll. Note that OIS.lib or OIS_d.lib is the same for the input system they load OIS_d.dll or OIS.dll. So we link Ogre 3D and OIS dynamically, enabling us to switch the DLL without recompiling our application, as long as the interface of the libraries doesn't change and the application and the DLL are using the same runtime library versions. This also implies that our application always needs to load the DLLs, so we have to make sure it can find it. This is one of the reasons we set the working directory in step 14. Another reason will be made clear in the next section.

ExampleApplication

We created a new class, Example1, which inherits from ExampleApplication. ExampleApplication is a class that comes with the Ogre 3D SDK and is intended to make learning Ogre 3D easier by offering an additional abstraction layer above Ogre 3D. ExampleApplication starts Ogre for us, loads different models we can use, and implements a simple camera so we can navigate through our scene. To use ExampleApplication, we just needed to inherit from it and override the virtual function createScene(). We will use the ExampleApplication class for now to save us from a lot of work, until we have a good understanding of Ogre 3D. Later, we will replace ExamplesApplication piece-by-piece with our own code.

In the main function, we created a new instance of our application class and called the go() function to start the application and load Ogre 3D. At startup, Ogre 3D loads three config files Ogre.cfg, plugins.cfg, and resources.cfg. If we are using the debug versions, each file needs an "_d" appended to its name. This is useful because with this we can have different configuration files for debug and release. Ogre.cfg contains the configuration we selected in the setup dialog, so it can load the same settings to save us from entering the same information every time we start our application. plugins.cfg contains a list of plugins Ogre should load. The most important plugins are the rendersystem plugins. They are the interface for Ogre to communicate with OpenGL or DirectX to render our scene. resources.cfg contains a list of resources that Ogre should load during startup. The Ogre 3D SDK comes with a lot of models and textures we will use in this book and resources.cfg points to their location. If you look inside resources.cfg, you will see that the paths in this file are relative. That's the reason we need to set the working directory.

Pop quiz — which libraries to link

  1. Which libraries do you need to link when using Ogre 3D in release configuration?

    a. OgreD3DRenderSystem.lib

    b. OgreMain.lib

    c. OIS.lib

  2. What would we have to change when we want to use the debug build versions of Ogre 3D?

    a. Add an _debug after the library name

    b. Add an _d at the file extension

    c. Add an _d after the library name