Skip to main content

History: Creating Overlays via Code

Preview of version: 6

%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:


Copy to clipboard
Ogre::OverlayManager& overlayManager = Ogre::OverlayManager::getSingleton(); // Create an 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 overlay->show();


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.


Copy to clipboard
OverlayManager& overlayManager = OverlayManager::getSingleton(); // Create a panel OverlayContainer* panel = static_cast<OverlayContainer*>( overlayManager.createOverlayElement("Panel", "PanelName")); panel->setMetricsMode(Ogre::GMM_PIXELS); 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->setMetricsMode(Ogre::GMM_PIXELS); textArea->setPosition(0, 0); textArea->setDimensions(100, 100); textArea->setCaption("Hello, World!"); textArea->setCharHeight(16); textArea->setFontName("TrebuchetMSBold"); 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"); overlay->add2D(panel); // Add the text area to the panel panel->addChild(textArea); // Show the overlay overlay->show();

See also


Alias: Creating_Overlays_via_Code

History

Information Version
Wed 30 of May, 2012 14:53 GMT-0000 Shinigami Added the "Ogre::Overlay*" type to the overlay identifier to allow for direct copy&paste of the code 7
Mon 07 of May, 2012 18:09 GMT-0000 uzik more minimal example that works included. Bug in Ogre release noted. 6
Tue 31 of Aug, 2010 20:13 GMT-0000 DragonM Add Ogre compatibility tag. 5
Tue 29 of Jun, 2010 14:05 GMT-0000 JustBoo 4
Sat 02 of Jan, 2010 20:26 GMT-0000 jacmoe 3
Fri 25 of Dec, 2009 13:36 GMT-0000 jacmoe 2
Wed 06 of May, 2009 19:24 GMT-0000 Spacegaier 1