Multiple techniques in material

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

Multiple techniques in material

Post by kondor9 »

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?
User avatar
Rasengan
Halfling
Posts: 46
Joined: Sun Jul 13, 2008 12:21 pm
Location: Brussels

Re: Multiple techniques in material

Post by Rasengan »

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.
User avatar
Kukanani
Halfling
Posts: 67
Joined: Thu Jun 12, 2008 11:42 pm
x 1

Re: Multiple techniques in material

Post by Kukanani »

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
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 »

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;
}