[Solved] Ogre RenderToTexture in MyGUI

Valcaris

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"/>
</MyGUI>


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,
Ogre::TU_RENDERTARGET);

// 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 );

camera->lookAt(Ogre::Vector3::ZERO);
camera->setNearClipDistance(1);

renderTexture->addViewport(camera);
renderTexture->getViewport(0)->setClearEveryFrame(false);
renderTexture->getViewport(0)->setBackgroundColour(Ogre::ColourValue::Black);

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

// send the RTT to the GUI
minimapCanvas->setRenderItemTexture(&oT);


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!

Altren

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>

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

Valcaris

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!

andrewfenn

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.

Altren

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? :)

andrewfenn

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);
renderTexture->getViewport(0)->setBackgroundColour(Ogre::ColourValue::ZERO);
renderTexture->getViewport(0)->setOverlaysEnabled(false);
renderTexture->update(true);

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

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

andrewfenn

10-07-2010 13:44:07

Ok I figured this out before I was calling

clearResourceGroup("BuildEditorIcons");

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

destroyResourceGroup("BuildEditorIcons");

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