OGRE Wiki
Support and community documentation for Ogre3D
Ogre Forums
ogre3d.org
Log in
Username:
Password:
CapsLock is on.
Remember me (for 1 year)
Log in
Home
Tutorials
Tutorials Home
Basic Tutorials
Intermediate Tutorials
Mad Marx Tutorials
In Depth Tutorials
Older Tutorials
External Tutorials
Cookbook
Cookbook Home
CodeBank
Snippets
Experiences
Ogre Articles
Libraries
Libraries Home
Alternative Languages
Assembling A Toolset
Development Tools
OGRE Libraries
List of Libraries
Tools
Tools Home
DCC Tools
DCC Tutorials
DCC Articles
DCC Resources
Assembling a production pipeline
Development
Development Home
Roadmap
Building Ogre
Installing the Ogre SDK
Setting Up An Application
Ogre Wiki Tutorial Framework
Frequently Asked Questions
Google Summer Of Code
Help Requested
Ogre Core Articles
Community
Community Home
Projects Using Ogre
Recommended Reading
Contractors
Wiki
Immediate Wiki Tasklist
Wiki Ideas
Wiki Guidelines
Article Writing Guidelines
Wiki Styles
Wiki Page Tracker
Ogre Wiki Help
Ogre Wiki Help Overview
Help - Basic Syntax
Help - Images
Help - Pages and Structures
Help - Wiki Plugins
Toolbox
Freetags
Categories
List Pages
Structures
Trackers
Statistics
Rankings
List Galleries
Ogre Lexicon
Comments
History: Displaying 2D Backgrounds
View page
Source of version: 14
(current)
A frequently asked question is how to display a 2D background image in OGRE. Here is an example of how to achieve this using the [http://www.ogre3d.org/docs/api/html/classOgre_1_1Rectangle2D.html|Rectangle2D] class. This also demonstrates e.g. how to easily scroll the background. {CODE(wrap="1", colors="c++")}// Create background material MaterialPtr material = MaterialManager::getSingleton().create("Background", "General"); material->getTechnique(0)->getPass(0)->createTextureUnitState("rockwall.tga"); material->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false); material->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false); material->getTechnique(0)->getPass(0)->setLightingEnabled(false); // Create background rectangle covering the whole screen Rectangle2D* rect = new Rectangle2D(true); rect->setCorners(-1.0, 1.0, 1.0, -1.0); rect->setMaterial("Background"); // Render the background before everything else rect->setRenderQueueGroup(RENDER_QUEUE_BACKGROUND); // Use infinite AAB to always stay visible AxisAlignedBox aabInf; aabInf.setInfinite(); rect->setBoundingBox(aabInf); // Attach background to the scene SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Background"); node->attachObject(rect); // Example of background scrolling material->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setScrollAnimation(-0.25, 0.0); // Don't forget to delete the Rectangle2D in the destructor of your application: delete rect; {CODE} __Note:__ You cannot add the 2D Rectangle directly to the root scene node. It will not show up. Here is the port to ((MOGRE)): {CODE(wrap="1", colors="c++")}// Create background material MaterialPtr material = MaterialManager.Singleton.Create("Background", "General"); material.GetTechnique(0).GetPass(0).CreateTextureUnitState("rockwall.tga"); material.GetTechnique(0).GetPass(0).DepthCheckEnabled = false; material.GetTechnique(0).GetPass(0).DepthWriteEnabled = false; material.GetTechnique(0).GetPass(0).LightingEnabled = false; // Create background rectangle covering the whole screen Rectangle2D rect = new Rectangle2D(true); rect.SetCorners(-1.0f, 1.0f, 1.0f, -1.0f); rect.SetMaterial("Background"); // Render the background before everything else rect.RenderQueueGroup = (byte)RenderQueueGroupID.RENDER_QUEUE_BACKGROUND; // Use infinite AAB to always stay visible AxisAlignedBox aab = new AxisAlignedBox(); aab.SetInfinite(); rect.BoundingBox = aab; // Attach background to the scene SceneNode node = mSmgr.RootSceneNode.CreateChildSceneNode("Background"); node.AttachObject(rect); // Example of background scrolling material.GetTechnique(0).GetPass(0).GetTextureUnitState(0).SetScrollAnimation(-0.25f, 0.0f);{CODE} !!See also * [http://www.ogre3d.org/docs/api/html/structOgre_1_1Rectangle.html|Rectangle] in Ogre API * ((-Overlay|Overlay)) * ((-Material|Material)) * ((-AABB|AABB)) --- Alias: (alias(Displaying_2D_Backgrounds))
Search by Tags
Search Wiki by Freetags
Latest Changes
Minimal Ogre Collision
Artifex Terra
OpenMB
Advanced Mogre Framework
MogreSocks
Critter AI
Mogre Add-ons
MOGRE
Mogre MyGUI wrapper
MOGRE Editable Terrain Manager
...more
Search
Find
Advanced
Search Help
Online Users
25 online users