Multiple techniques in material

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
kondor9
Gnoblar
Posts: 1
Joined: Thu May 21, 2009 5:54 pm

Multiple techniques in material

Post by kondor9 » Thu May 21, 2009 6:13 pm

Welcome

i have one question, how can i change manualy techniques in material?

i have material "one" with two technique "one" and "two". Ogre always use technique "one" but i need use technique "two".
How can i make function to manualy change technique in material?
0 x

User avatar
Rasengan
Halfling
Posts: 46
Joined: Sun Jul 13, 2008 12:21 pm
Location: Brussels

Re: Multiple techniques in material

Post by Rasengan » Fri May 22, 2009 10:19 pm

Hey,

not so hard at all, you can get your material with MaterialManager class.

You can get your techniques, simply by passing index or names, as well as passes, texture units...etc.
You can dynamically change your techniques for sure, here is a very simple example wich show how to change a "technique attribute" with the code. I hope it can help you.

Code: Select all

Ogre::MaterialPtr matPtr = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingletonPtr()->getByName("one"));
Ogre::Technique* tech = matPtr->getTechnique("two");
tech->getPass(yourPassNameOrIndex)->setPolygonMode(Ogre::PM_WIREFRAME);
Easy, this code will set your specific material to wireframe mode.
You can set/add textures, shaders, blending modes....everything that Ogre::Material can do...

I'don't know how to force Ogre to choose a Technique(getBestTechnique() is the first declared technique wich is supported), it's seems that there is not some "Material::SetTechnique()" built in function but you can always "remove" your first technique dynamically if you want, so Ogre will take your Technique "two" automatically...
Last edited by Rasengan on Mon May 25, 2009 11:34 am, edited 1 time in total.
0 x

User avatar
Kukanani
Halfling
Posts: 67
Joined: Thu Jun 12, 2008 11:42 pm

Re: Multiple techniques in material

Post by Kukanani » Sat May 23, 2009 11:56 pm

Hi,
I'm trying to do what you said about removing the technique by name, but the removeMaterial() method only takes a short int as an argument. Is there a way around this?
Thanks,
Kukanani
0 x
Grammar is the greatest joy in life, don't you find?

--Aunt Josephine in The Wide Window

User avatar
Rasengan
Halfling
Posts: 46
Joined: Sun Jul 13, 2008 12:21 pm
Location: Brussels

Re: Multiple techniques in material

Post by Rasengan » Mon May 25, 2009 11:12 am

Ho, sry, you can get a technique by name but not remove it by name.
You can try this:

Code: Select all

Ogre::Material::TechniqueIterator it = matPtr->getTechniqueIterator();
				
unsigned int index = 0;
while (it.hasMoreElements())
{
  Ogre::Technique* tech = it.getNext();
  if ("TechNameToRemove" == tech->getName())
  {
    matPtr->removeTechnique(index);
    break; // or add a bool if you want...
  }
  ++index;
}
0 x

Post Reply