Changing Materials at Runtime.

Problems building or running the engine, queries about how to use features etc.
Post Reply
Mdobele
Halfling
Posts: 55
Joined: Mon Jun 07, 2004 11:01 am
Contact:

Changing Materials at Runtime.

Post by Mdobele »

Simple prob I hope. I am simply just trying to change the material applied on one box to another using the setMaterialName();

I have 2 Boxes in my scene. I try to change the left box to use the right boxes Material but it always goes white and the error log always says that the material does not exsist. But it does as the right box is using it in the first place. I have checked that the name is correct. When changing the material to an already created entity is there anything you have to do for it to take effect?

Here is a pic. Trying to chnge 1 sub entity to the Box 2 material
Image


And just to be completely exact. Here is the simple Material file beeing used. Know to OGRE as it uses them to begin with during loading.

Code: Select all

material Box2
{
	technique
	{
		pass
		{
			ambient 0.113725 0 0.980392 1
			diffuse 0.113725 0 0.980392 0
			specular 0.9 0.9 0.9 0 0
		}
	}
}
material Box1
{
	technique
	{
		pass
		{
			ambient 1 0 0 1
			diffuse 1 0 0 0
			specular 0.9 0.9 0.9 0 0
		}
	}
}
PrimedGames
www.PrimedGames.com

Email Me At
Mdobele( AT )primedgames.com
// Replace AT with @ of course
User avatar
spookyboo
Silver Sponsor
Silver Sponsor
Posts: 1141
Joined: Tue Jul 06, 2004 5:57 am
x 151
Contact:

Post by spookyboo »

If you only change the colours, you can:
1. Get the pointer to a specific material, using the MaterialManager and the getByName ("Box2");
2. Get the pass using Pass* pass = material->getTechnique(0)->getPass(0);
3. Set colours, i.e. pass-setAmbient()...
Mdobele
Halfling
Posts: 55
Joined: Mon Jun 07, 2004 11:01 am
Contact:

Post by Mdobele »

Thanks but that is just a simple test case. I will need it to support changing an actuall material file. The only thing I can think of is that when loading a .scene file it has put the relative paths out. So the paths that i have set up in the resources.cfg file are no longer correct and OGRE cannot find the Material anymore. I dunno it has to be somthing simple but its driving me nuts :?
PrimedGames
www.PrimedGames.com

Email Me At
Mdobele( AT )primedgames.com
// Replace AT with @ of course
Mdobele
Halfling
Posts: 55
Joined: Mon Jun 07, 2004 11:01 am
Contact:

Post by Mdobele »

Ok with a little more testing I have found that if I am changing my entity to use a material that contains a Texture then it works fine.

But if I try to change it to any material that is simply using the colour techniqe as above it doesnt work and Ogre always complains that it cant find the material. Anyone got any thoughts?
PrimedGames
www.PrimedGames.com

Email Me At
Mdobele( AT )primedgames.com
// Replace AT with @ of course
Mdobele
Halfling
Posts: 55
Joined: Mon Jun 07, 2004 11:01 am
Contact:

Post by Mdobele »

HA HA HA HA HA I Knew it had to be something simple.

Getting the name from the CEGUI edit box would always return one piece of WhiteSpace on the end of my string. So instead of looking for
"Box2" It was looking for "Box2 " <-- Space at end. That nasty little whitespace you kinda dont notice when your logging it out :oops:

Its all good now.
PrimedGames
www.PrimedGames.com

Email Me At
Mdobele( AT )primedgames.com
// Replace AT with @ of course
Post Reply