I am trying to make CEGUI render to a specific texture unit in a material.
The goal is to enable rendering of any number of GUIs into any arbitrary texture units at the same time.
But I already fail with only one
My code is the following:
Code: Select all
// Create CEGUI renderer
CEGUI::OgreRenderer& renderer =
CEGUI::OgreRenderer::bootstrapSystem(
*static_cast<Ogre::RenderTarget*>(p_window->getOgreWindow())
);
// Set resource paths
CEGUI::ImageManager::setImagesetDefaultResourceGroup("Gui");
CEGUI::Font::setDefaultResourceGroup("Gui");
CEGUI::Scheme::setDefaultResourceGroup("Gui");
CEGUI::WidgetLookManager::setDefaultResourceGroup("Gui");
CEGUI::WindowManager::setDefaultResourceGroup("Gui");
// Init CEGUI
CEGUI::ImageManager::getSingleton().loadImageset("TaharezLook.imageset", "Gui");
CEGUI::SchemeManager::getSingleton().createFromFile("TaharezLook.scheme", "Gui");
// Load a layout
CEGUI::Window* window = CEGUI::WindowManager::getSingleton()
.loadLayoutFromFile((CEGUI::utf8*)"TextSample.layout");
window->setUsingAutoRenderingSurface( true );
// Get the Ogre texture
CEGUI::OgreTextureTarget& textureTarget =
dynamic_cast<CEGUI::OgreTextureTarget&>(window->getRenderingSurface()->getRenderTarget());
CEGUI::Texture& ceTex = textureTarget.getTexture();
CEGUI::OgreTexture& ogreTexture = static_cast<CEGUI::OgreTexture&>(ceTex);
Ogre::TexturePtr ogreTexturePtr = ogreTexture.getOgreTexture();
// Find the material
Ogre::MaterialPtr matPtr = Ogre::MaterialManager::getSingleton().getByName("FullscreenOverlay");
// Find the technique
Ogre::Technique* technique = matPtr->getTechnique("Tech");
// Find the pass
Ogre::Pass* pass = technique->getPass("Pass");
// Find the texture unit, get its original texture and replace the texture
Ogre::TextureUnitState* textureUnit = pass->getTextureUnitState("Texture");
Ogre::String name = ogreTexturePtr->getName();
textureUnit->setTextureName(name);
It does successfully replace the texture on the material, but only with a black, transparent texture.
I assume that CEGUI never really renders into the texture, but how can I make it?
The logs do not show anything strange, so I suspect I am forgetting something here.
As an additional info, the material is on a compositor pass rendering a fullscreen quad.
Also, I am using the latest bitbucket version of 0.8.
I also read the article about general RTT ( this one ), but I do not even know where to start with that approach. How would you load and display a layout with that? When would you have to call that .draw()-function in Ogre (maybe within a RenderTargetListener?). Do you create such a context per loaded layout or per texture you want to render to?
It leaves so many open questions that I thought the above approach would be better suited.