How to dynamically change texture/material in TSE?
by Justin Tolchin · in Torque Game Engine Advanced · 04/20/2005 (4:56 pm) · 8 replies
Hi all,
A nice newbie question for ya! :-)
There used to be something called "setOverrideTexture" in TGE but it appears it's been removed from TSE. What I need is way to take a model and dynamically change the texture, or better yet add & remove a semi-transparent texture over the top of it (for example, to give the model a temporary blue-ish tint or whatever). What's the easiest way to go about this in TSE?
Thanks!
A nice newbie question for ya! :-)
There used to be something called "setOverrideTexture" in TGE but it appears it's been removed from TSE. What I need is way to take a model and dynamically change the texture, or better yet add & remove a semi-transparent texture over the top of it (for example, to give the model a temporary blue-ish tint or whatever). What's the easiest way to go about this in TSE?
Thanks!
#2
I *thought* maybe all I needed to do was modify the value of TSShapeInstance::smRenderData.materialIndex to the index of my override texture. To do that I needed to add my override material to the list using (I'm guessing) mMaterialList->push_back(). So I tried that and stored the index returned by the push_back call and tried to use it (in the TSMesh::setMaterial call) to set the texture index based on whether or not the smRenderData::useOverride flag was set. Unfortunately that didn't work because the useOverride flag never gets set. That flag is supposed to be set in something called setStatics but setStatics never gets called. :-( I'm not sure where that's supposed to be called from. There are a couple of places where it's commented out; TSPartInstance::render seemed the most likely place but that method never gets called either.
04/21/2005 (10:55 am)
Well actually it looks like it's a bit more complicated than that. Setting the override texture just sets some properties (TSShapeInstance::RenderData.override) that don't get used in the new TSE code. It's all old "gl" code that's commented out (i.e. TSMesh::setMaterial) and that I don't understand anyway. I *thought* maybe all I needed to do was modify the value of TSShapeInstance::smRenderData.materialIndex to the index of my override texture. To do that I needed to add my override material to the list using (I'm guessing) mMaterialList->push_back(
#3
If you are lazy, just add a global bool somewhere that the function can set, as well as a global TexHandle to store the override texture if any. Then in GFX::setTexture, have it check the bool and if its set, force the TU to use the specified texture. Only do this for texture stage 0. Poof! Override textures. Don't forget to clear the override when you're done rendering a TS! :)
04/21/2005 (11:09 am)
Yikes, I think you got sucked down the rabbit hole! :)If you are lazy, just add a global bool somewhere that the function can set, as well as a global TexHandle to store the override texture if any. Then in GFX::setTexture, have it check the bool and if its set, force the TU to use the specified texture. Only do this for texture stage 0. Poof! Override textures. Don't forget to clear the override when you're done rendering a TS! :)
#4
Thanks, I'll give that a try.
04/21/2005 (11:16 am)
As a matter of fact... I am lazy! How lucky for me. :-) Thanks, I'll give that a try.
#5
EDIT: never mind. I figured it out. :-)
04/21/2005 (4:00 pm)
Hmmm... now I'm confused. If I set the texture override flag, how do I know *which* object is being drawn in the GFXDevice::SetTexture method? I only want to override the texture for one object.EDIT: never mind. I figured it out. :-)
#6
04/21/2005 (11:34 pm)
You don't care. Just set the flag when you start drawing, and clear it when you're done.
#7
As Ben indicates on the thread, I put the check for the boolean and the texture swap into GFXDevice::SetTexture, however now Im confused about where exactly shall I change the bool value (the one that determines when my texture should be used).
On TGE setOverrideTexture was called in my case from a RenderObject method. So what I tried, in simple pseudocode, would be something like this:
But GFXDevice::SetTexture seems to be called after my::RenderObject(), so the bool change has no effect at all now.
Now I know that the changes in GFXDevice::SetTexture works, because if I set the bool to true, and never change it back to false, the whole screen is painted with my override texture. My problem is that I dont know where to put the bool=false, to make the texture change affect only the object I want (which btw, is derivative of TSStatic).
06/11/2008 (6:38 pm)
Sorry about the necro-thread rising, but I was trying to implement this, and found some problems. As Ben indicates on the thread, I put the check for the boolean and the texture swap into GFXDevice::SetTexture, however now Im confused about where exactly shall I change the bool value (the one that determines when my texture should be used).
On TGE setOverrideTexture was called in my case from a RenderObject method. So what I tried, in simple pseudocode, would be something like this:
my::RenderObject()
{
...
bool = true; // this used to be setOverrideTexture
render;
bool = false; // this used to be clearOverrideTexture
...
}But GFXDevice::SetTexture seems to be called after my::RenderObject(), so the bool change has no effect at all now.
Now I know that the changes in GFXDevice::SetTexture works, because if I set the bool to true, and never change it back to false, the whole screen is painted with my override texture. My problem is that I dont know where to put the bool=false, to make the texture change affect only the object I want (which btw, is derivative of TSStatic).
#8
06/12/2008 (4:13 pm)
Pump it up!
Associate Kyle Carter