updating textures with ItemBox


14-09-2015 11:38:54


I'm using item boxes to display 3d objects thumbnails.
Sometimes, the user can update the 3D meshes and textures at runtime, and I re-generate all the thumbnails.
But I can't find a way to reload the items textures in the itembox.
I'm deleting all the items and re-create them, and I'm re-loading the textures like this :

Ogre::TextureManager::getSingleton().unload(iconName + ".tga");
Ogre::TextureManager::getSingleton().load(iconName + ".tga", "Media");
MyGUI::ResourceManager::getInstance().load(iconName + ".tga");

But the icons are not updated until I close and re-open the .exe.
What I am doing wrong ? Do I have to update the imageSets too?


14-09-2015 20:49:02

Try to use texturePtr->unload(); and TextureManager::remove instead of TextureManager::unload .
Basically this is pure Ogre question, since MyGUI use Ogre textures.


15-09-2015 12:28:15

Thanks for your answer!

I understand that MyGUI uses Ogre textures. This is why I don't understand my problem:
-if I reload the icon texture, and use it on a mesh material, it's updated in Ogre
-but not in MyGUI

How could two different versions of the same texture exist in memory?


15-09-2015 13:14:52

Try to use some texture on mesh and make sure, that your reload logic works.
If it does show me the code you used and I'll try to make MyGUI texture reload. I'm not sure where the problem is, but after checking OgrePlatform code I don;t see any reason why rendered texture would not update if underlying texture was reloaded.


19-09-2015 18:11:14

Hi Altren,

This is what I do:
In my level editor I can add or delete meshes or textures at runtime.
In my example, I'm using the teapot Icon as a diffuse texture for the teapot :

I'm modifying the original diffuse texture of the teapot and paint it yellow.
So, when user goes back to the editor, I update the resources like this (where the meshes, textures and all the editor Icons are stored) :

Then, I update the itemBox icon's textures like this:
Ogre::TexturePtr tex = Ogre::TextureManager::getSingleton().getByName("icon_teapot.tga", Game::getSingletonPtr()->gameName);

I can then use this texture on a mesh, like this:
And it works well: I can see the texture on a mesh.
But the itemBox icons are not being updated at all...
They will be updated the next time I close and re-open the .exe, though.



19-09-2015 23:11:00

Try clearing all MyGUI references to the texture after you've unloaded it in Ogre.



21-09-2015 09:34:12

I tried a lot of things, and nothing works. I tried to clear the references, and it does nothing new...
I must say I have problems understanding the inner working of the resources in Ogre...
It makes me crazy, because I'm completely lost, and I spent days trying to update this imageBox :(

Anyway, thanks a lot for helping me.

Crystal Hammer

22-09-2015 06:40:41

Yeah I had a lot of trouble with similar thing too, updating images on MyGui ImageBox, from basically same named files but in different subdirs (paths).
This was a PITA with resources and I ended writing a class that wraps an Ogre texture and loads it directly from disk path, not using any bloody resources.
Only drawback is probably that I need to know the size, maybe could be extended, but I didn't need that.

Sources are here:
Then using it in code is very simple:

// variable in my app class
PreviewTex loadTex;
// code in scene init, in createScene(), done once
loadTex.Create(1920,1200,"LoadingTex"); // known image dimensions

// update code, load or reload other image from path
loadTex.Load(PATHMANAGER::Data()+"/loading/loading" +toStr(imgNumber+1)+ ".jpg");
imgLoad->setImageTexture("LoadingTex"); // ImageBox* imgLoad; is in app class, using just texture name, which stays the same

Also the path that has images loaded with PreviewTex is not listed in Ogre resources.cfg. No need and proably could cause trouble.


23-09-2015 08:20:16

Thanks a lot Crystal Hammer!
I'll try your class in a few days, when I'll have a little more time on my hands.