Skip to main content
Render entitys to rttTex         Rendering an Entity to a texture for use in HUDS and the like

on RPG game, we always can see the equipWindow has a real-render Model,
now we have a way to impl it.

Copy to clipboard
const unsigned int SHOW_ENTITY_ON_MAIN_VIEWPORT_FLAG = 1; const unsigned int SHOW_ENTITY_ON_OTHER_VIEWPORT_FLAG = 1 << 1; //or 1 << n const unsigned int SHOW_ENTITY_ON_ALL_VIEWPORT_FLAG = 0xFFFFFFFF; void createCameraLook(const std::string& CameraName, const std::string& TextureName, unsigned int mask = 1 << 1, const Ogre::Vector3& CameraPos = Ogre::Vectir3(0,1,3), const Ogre::Vector3& lookPos = Ogre::Vector3(0,1,0)) { //create a camera look this scenenode(attached entitys) Ogre::Camera* pCameraLookMe = pOgreSceneMgr->createCamera(CameraName); pCameraLookMe->setPosition(CameraPos); pCameraLookMe->lookAt(lookPos); pCameraLookMe->setAutoTracking(true, m_pSceneNode, lookPos); pCameraLookMe->setFarClipDistance(0); pCameraLookMe->setNearClipDistance(1.0); pCameraLookMe->setAutoAspectRatio(true); pSceneNode->attachObject(m_pCameraLookMe); //let's create a rttTex and take the camera Ogre::TexturePtr pRttCameraLookMe = Ogre::TextureManager::getSingleton().createManual( TextureName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, 128, 128, 0, Ogre::PF_DXT5, Ogre::TU_RENDERTARGET ); Ogre::RenderTarget *rttTex = pRttCameraLookMe->getBuffer()->getRenderTarget(); Ogre::Viewport* pVp = rttTex->addViewport(pCameraLookMe); //alpha background pVp->setBackgroundColour(Ogre::ColourValue(0,0,0,0)); //i just set the mainRenderWnd's viewport's visibilitymask to 1, //so this viewport need to set 1 << 1, if you add more the mask must 1 << n pVp->setVisibilityMask(mask); //this viewport don't need sky,shadow,overlay pVp->setOverlaysEnabled(false); pVp->setSkiesEnabled(false); pVp->setShadowsEnabled(false); //every frame render,or not rttTex->setAutoUpdated(true); } //after, you can set the entity's visibilityFlag as you need it to show on which viewport. pEntity->setVisibilityFlags(SHOW_ENTITY_ON_MAIN_VIEWPORT_FLAG | (1 << 1));
Copy to clipboard

now you can take the rttTex to render to everywhere as you like.