[Solved] Ogre RenderToTexture in MyGUI


24-01-2010 01:49:59

I'm trying to figure out how to show a RTT in MyGUI.

I've poked around the forums a bit and I've found a class called MyGUI::Canvas and I tried calling its setRenderItemTexture() function, but I don't seem to get anything showing up. Here are some snippets:

My layout file:
<?xml version="1.0" encoding="UTF-8"?>
<MyGUI type="Layout">
<Widget type="Canvas" skin="Canvas" position_real="0.75 0.75 0.25 0.25" layer="Main" name="Minimap"/>

My code (doctored slightly):

// create the texture for the RTT
Ogre::TexturePtr m_texture;
m_texture = Ogre::TextureManager::getSingleton().createManual("MinimapTex",
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D,
128, 128, 0, Ogre::PF_R8G8B8,

// the RTT will receive data from a Camera which is set up below
Ogre::RenderTexture* renderTexture = m_texture->getBuffer()->getRenderTarget();
Ogre::Camera* camera = m_sceneManager->createCamera("MinimapCamera");
Ogre::SceneNode* cameraNode = m_sceneManager->getRootSceneNode()->createChildSceneNode("MinimapCameraNode", Ogre::Vector3( 0, 5000.0, 0 ) );
cameraNode->attachObject( camera );



// set up the MyGUI stuff
MyGUI::OgreTexture oT("blahTex", "blahG");
MyGUI::CanvasPtr minimapCanvas = gui->findWidget<MyGUI::Canvas>("Minimap");

// send the RTT to the GUI

Everything seems to compile fine, but it throws an exception in MyGUI_RenderItem.cpp line 95:
MYGUI_EXCEPT("texture pointer is not valid, texture name '" << mTextureName << "'");

Any help, ideas, or suggestions would be appreciated. Thanks!


24-01-2010 02:20:25

Well, you should've looked that this is completely not Canvas method.
All that you need is forget about Canvas and use next code:
<?xml version="1.0" encoding="UTF-8"?>
<MyGUI type="Layout">
<Widget type="StaticImage" skin="StaticImage" position_real="0.75 0.75 0.25 0.25" layer="Main" name="Minimap"/>

MyGUI::StaticImagePtr minimap = gui->findWidget<MyGUI::StaticImage>("Minimap");
minimap ->setImageTexture("MinimapTex");


24-01-2010 03:56:42

Wow, thanks for the quick response.

I had seen the StaticImage Widget and I thought I had tried it, but something must have not been quite right. It does seem to be rendering now.

Thanks a bunch for your help!


04-07-2010 18:08:11

I have been updating my code to use 3.3.x however I have noticed that in MyGUI 3.3.x you can no longer call setImageTexture multiple times to update the image. Is this correct or am I doing something stupid? The code works in the 2.2.x series.


05-07-2010 08:41:04

I'm not sure why this happening, but try to set empty texture ("") and then yours texture again to force update.
And btw - we don't have MyGUI 3.3.* yet. Are you from future? :)


05-07-2010 15:58:36

Tried that but no joy and sorry I meant 3.0.1 :D

Here's a snippet without the extra empty function call.

Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().createManual(lPanelName, "BuildEditorIcons",
Ogre::TEX_TYPE_2D, 512, 512, 0, Ogre::PF_R8G8B8A8, Ogre::TU_RENDERTARGET );
Ogre::RenderTexture *renderTexture = texture->getBuffer()->getRenderTarget();

renderTexture->addViewport(lCamera, 0);
renderTexture->getViewport(0)->setDimensions(0, 0, 1, 1);

mBoxMgr.addItem(new ItemBox(lPanelName, lPanelName, lMesh));

mImage = MyGUI::Gui::getInstancePtr()->findWidget<MyGUI::StaticImage>(_panel);


10-07-2010 13:44:07

Ok I figured this out before I was calling


However just clearing the resource group doesn't seem to clear the old render texture data so now I use


and then create it again. That seems to be working now.