Updating textures on the fly!

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Jenny
Posts: 13
Joined: Mon Nov 21, 2005 1:58 am

Updating textures on the fly!

Post by Jenny »

Hello im looking to use a list of textures that are hardcoded in a list.
I then want to call these textures with a timer event so many seconds
and change a string value to the new texture name on each timer event.

Im prety sure it will change the actual string value but will the texture on the node change on the fly or will I have to reload the node?

Example might be something like this.

list tex = ["tex1","tex2","tex3","tex4"];

string current tex = "tex1";

//// some kind of event with timer to increment through the list ////


IAnimatedMeshSceneNode* nodetree1 = 0;
IAnimatedMesh* meshtree1 = smgr->getMesh(
"../../media/tree.3ds");

nodetree1 = smgr->addAnimatedMeshSceneNode(meshtree1);
nodetree1->getMaterial(0).EmissiveColor.set(0,0,0,0);
nodetree1->setPosition(core::vector3df(21200,980,8500));
nodetree1->setScale(core::vector3df(5.5,8.5,5.5));
nodetree1->setMaterialTexture(0, driver->getTexture(current tex));

Blah blah incomplete code lol.

But lets say I wanted to change texture of the tree from a nice green one
to a very snowy looking tree in incremeting stages.
Ok lol its just an example lol

But anyway how would I update the nodes texture?

Thanks you guys for any help
Last edited by Jenny on Mon Nov 21, 2005 2:43 am, edited 1 time in total.
Conquistador
Posts: 340
Joined: Wed Sep 28, 2005 4:38 pm
Location: Canada, Eh!

re:

Post by Conquistador »

Why don't you load all the textures before hand, then just change the pointer to the texture on the mesh? Working with strings like that can be tricky, if you do all the loading before hand, you will be able to check if the textures have been loaded or not.
Jenny
Posts: 13
Joined: Mon Nov 21, 2005 1:58 am

Post by Jenny »

Interesting/
Im not quite sure what you mean by PRELOAD the textures?
Load them on what and load them into what?
It would still need to be in memory someplace and then be reloaded
onto the mesh right?
You got any examples to what your point is your making im kinda not
sure to what your saying here?
Thanks for your responce too by the way.
Conquistador
Posts: 340
Joined: Wed Sep 28, 2005 4:38 pm
Location: Canada, Eh!

Post by Conquistador »

Code: Select all

// Load the textures
ITexture* Texture1 = Driver->getTexture("media/image1.jpg");
ITexture* Texture2 = Driver->getTexture("media/image2.jpg");

// Check to see if the textures loaded
if (!Texture1 || !Texture2)
{
   // Error
}

// Set the texture
Mesh->setMaterialTexture(0, Texture1);

while (Device->run())
{
   if (time_to_update_texture)
   {
      Mesh->setMaterialTexture(0, Texture2);
   }
}
You'll have to fill in the blanks, but that's a very, very vage way of how it should be done. A better way would to store the textures in a list, and just iterate through the textures when the time comes.
Jenny
Posts: 13
Joined: Mon Nov 21, 2005 1:58 am

Post by Jenny »

I see you located it in the while loop of the device run?
Is this where it should be or could one create a event reciver?
And the list is what I was asking about in the first place.
But your idea looks fine as well just kinda makes me wonder
if those textures are actually being loaded and stored anyplace
at all or if they are and are taking up system mem?
Conquistador
Posts: 340
Joined: Wed Sep 28, 2005 4:38 pm
Location: Canada, Eh!

re:

Post by Conquistador »

Yes, those textures are being loaded into memory when that happens. And when referring to the list thing, I was refering more to a list of pointers to textures, so that you you can iterate through them that way. Using strings like that is pretty risky, and, you'll be stuck loading the textures while the game is running, which will stop your program from running until the texture is loaded.

As for the event receiver, you shouldn't need one for a timer, because there's no timer events passed to OnEvent. You should do a timer thing like this:

Code: Select all

ITimer* Timer = Device->getTimer();
u32 nextTexChange = Timer->getRealTime() + 1000;

while (Device->run())
{
   if (Timer->getRealTime() >= nextTexChange)
   {
      // Change the texture

      nextTexChange += 1000;
   }
}
Jenny
Posts: 13
Joined: Mon Nov 21, 2005 1:58 am

Post by Jenny »

How about this idea?

list tex ["tex1","tex2"];
string current_tex = "tex1";


/// CREATE THE TIMER TO INCREMENT THE LIST ///
//// CHANGE THE CURRENT_TEX TO THE NEW IN LIST ///


nodetree1 = smgr->addAnimatedMeshSceneNode(meshtree1);
nodetree1->getMaterial(0).EmissiveColor.set(0,0,0,0);
nodetree1->setPosition(core::vector3df(21200,980,8500));
nodetree1->setScale(core::vector3df(5.5,8.5,5.5));
nodetree1->setMaterialTexture(0, driver->getTexture(current_tex));


/// USE THE DEVICE RUN LOOP TO UPDATE THE CURRENT_TEX ON TIMER //

while (Device->run())
{
if (time_to_update_texture)
{
meshtree1->setMaterialTexture(0, current_tex);
}
}

If you see anything wrong here please let me know.

I want to thank you for all your help too.
Conquistador
Posts: 340
Joined: Wed Sep 28, 2005 4:38 pm
Location: Canada, Eh!

re:

Post by Conquistador »

It looks like it should work, as long as the textures aren't being loaded in the main loop..
Jenny
Posts: 13
Joined: Mon Nov 21, 2005 1:58 am

Post by Jenny »

Oh I now see what your saying about the changing the texture my way.
I dont want the game to lag while loading the texture so yes maybe
your way might be the best ill just create a small file with all this and
see if I can create a function out of it to use when needed.

Thank you very much for your info its been good info and ive saved this
post in a notecard so I can refer to it again latter if I wish.

Thanks very much for your time.
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

Code: Select all

meshtree1->setMaterialTexture(0, current_tex);
shouldn't that be

Code: Select all

meshtree1->setMaterialTexture(0, driver->getTexture(current_tex));
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Jenny
Posts: 13
Joined: Mon Nov 21, 2005 1:58 am

Post by Jenny »

Yes bit I do belive so!

I havent even started to test this out yet lol.
I think we was just brain storming more then anything.
Im going to try a few diff ways of this and see what works smooth.
Again thanks for you guys help.
krama757
Posts: 451
Joined: Sun Nov 06, 2005 12:07 am

Post by krama757 »

If the textures are small enough though, you will probably want them to load during run-time. It wont lag it, and will keep system mem free for other things like terrain triangle selectors ^_^
Conquistador
Posts: 340
Joined: Wed Sep 28, 2005 4:38 pm
Location: Canada, Eh!

Post by Conquistador »

bitplane wrote:

Code: Select all

meshtree1->setMaterialTexture(0, current_tex);
shouldn't that be

Code: Select all

meshtree1->setMaterialTexture(0, driver->getTexture(current_tex));
Not really, I've used my method (without the Driver->getTexture(*pointer)) since I've been using the engine, and all my projects work fine..

The setMaterialTexture function takes a parameter of ITexture*, and all you're doing by getting the texture through Driver->getTexture() is making an extra function call.
Post Reply