OGRE (Object-Oriented Graphics Rendering Engine)

Setting Up the Scene

A scene in outer space

When we derive our own application class from the ExampleApplication class we overrride the protected method createScene whose prototype is:

As you can see this is a purely virtual function, so if we do not override it then we will get a nasty error. This method is responsible for setting up the scene within the application. This involves creating entities, lights, particle systems, etc.

It's time to get into the code, so if you have not done so already create an application following the previous steps and call it Space. To begin with we are going to create a scene from outer space, with planets visible in the distance based on the Skybox example.

Create a new header file called SpaceApplication.h. This is the file that we included in Space.cpp and is where we are going to define our own class SpaceApplication. The first thing we need to do is

    #include "ExampleApplication.h"

This gives us access to the ExampleApplication class that our application class is derived from. Now to create our class definition

    class SpaceApplication : public ExampleApplication
    {
    protected:
        void createScene(void);
    };

Now to override that createScene method with our own. There is only one thing we are interested in doing right now, create a skybox that shows us a scene in outer space. We do this by using the Scene Manager (mSceneMgr).

        void SpaceApplication::createScene(void)
        {
           // Create a skybox
            mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox");

        }

Compile and run the program. After the Ogre configuration box is gone you should be thrust into our space scene. The mouse will let you look left, right, up, and down. Time for a quick look at "Examples/SpaceSkyBox".

Resources

When we set the sky box we told the Scene Manager to use the material "Examples/SpaceSkyBox". But where does this come from? When an ExampleApplication class is created it tells the Resource Manager to add the following places to search for resources

            ../../../Media/dragon.zip
            ../../../Media/knot.zip
            ../../../Media/skybox.zip
            ../../../Media/

The Resource Manager searches those paths for a files ending in ".material" for definitions of materials. This material, Examples/SpaceSkyBox, happens to be defined in Example.material

    // Skybox
    material Examples/SpaceSkyBox
    {
    	technique
    	{
    		pass
    		{

    			// No dynamic lighting, fully lit
    			lighting off
    			// Depth writing off (always display stuff in front of it)
    			depth_write off

    			// Texture layer 0
    			texture_unit
    			{
    				// 6-sided texture, stevecube_fr.jpg, stevecube_up.jpg etc
    				cubic_texture stevecube.jpg separateUV
    				// clamp to avoid fuzziness at edges due to filtering
    				tex_address_mode clamp
    			}
    		}
    	}
    }

So this material is composed of 6 jpeg files, as listed in the definition. Those particular files can be located in the skybox.zip file.

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