Creating Overlays via Code         Without using overlay scripts

%ogre17%%ogre16% 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