Creating Overlays via Code         Without using overlay scripts

Ogre 1.7
Ogre 1.6
This code snippet demonstrates how to create Overlays? using code.

Here's a code snippet that shows the absolute minimal overlay functionality. It displays a solid white rectangle on the
screen at the top left corner:

Ogre::OverlayManager& overlayManager = Ogre::OverlayManager::getSingleton();
         // Create an overlay
         Ogre::Overlay* overlay = overlayManager.create( "OverlayName" );
         // Create a panel
         Ogre::OverlayContainer* panel = static_cast<Ogre::OverlayContainer*>( overlayManager.createOverlayElement( "Panel", "PanelName" ) );
         panel->setPosition( 0.0, 0.0 );
         panel->setDimensions( 0.1, 0.1 );
         panel->setMaterialName( "BaseWhite" );
         // Add the panel to the overlay
         overlay->add2D( panel );
         // Show the overlay

It uses no external materials or fonts.

As of this time the following code doesn't work due to a bug in the Ogre release. The created texture it
uses is not created before it's first use. The overlay code then fails and nothing will be displayed.

You'll need to include OgreTextAreaOverlayElement.h and OgreFontManager.h for this snippet to compile.

OverlayManager& overlayManager = OverlayManager::getSingleton();
// Create a panel
OverlayContainer* panel = static_cast<OverlayContainer*>(
    overlayManager.createOverlayElement("Panel", "PanelName"));
panel->setPosition(10, 10);
panel->setDimensions(100, 100);
//panel->setMaterialName("MaterialName"); // Optional background material
// Create a text area
TextAreaOverlayElement* textArea = static_cast<TextAreaOverlayElement*>(
    overlayManager.createOverlayElement("TextArea", "TextAreaName"));
textArea->setPosition(0, 0);
textArea->setDimensions(100, 100);
textArea->setCaption("Hello, World!");
textArea->setColourBottom(ColourValue(0.3, 0.5, 0.3));
textArea->setColourTop(ColourValue(0.5, 0.7, 0.5));
// Create an overlay, and add the panel
Overlay* overlay = overlayManager.create("OverlayName");
// Add the text area to the panel
// Show the overlay


See also

Alias: Creating_Overlays_via_Code

Contributors to this page: Shinigami72 points  , uzik979 points  , Spacegaier6073 points  , JustBoo , jacmoe180265 points  and DragonM1534 points  .
Page last modified on Wednesday 30 of May, 2012 14:53:42 UTC by Shinigami72 points .

The content on this page is licensed under the terms of the Creative Commons Attribution-ShareAlike License.
As an exception, any source code contributed within the content is released into the Public Domain.