Updating textures on the fly!
Updating textures on the fly!
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
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:
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.
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.
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!
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);
}
}
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?
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:
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:
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;
}
}
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.
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:
It looks like it should work, as long as the textures aren't being loaded in the main loop..
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.
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.
Code: Select all
meshtree1->setMaterialTexture(0, current_tex);
Code: Select all
meshtree1->setMaterialTexture(0, driver->getTexture(current_tex));
-
Conquistador
- Posts: 340
- Joined: Wed Sep 28, 2005 4:38 pm
- Location: Canada, Eh!
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..bitplane wrote:shouldn't that beCode: Select all
meshtree1->setMaterialTexture(0, current_tex);Code: Select all
meshtree1->setMaterialTexture(0, driver->getTexture(current_tex));
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.