Material problems

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
kohansey
Posts: 14
Joined: Tue Apr 01, 2008 3:18 am

Material problems

Post by kohansey »

Hello everyone,

I am still relatively new to Irrlicht and need some help working with materials. I created a custom scene node, and I have been successful in getting the scene node to display a loaded 3DS mesh. Now I want to add texture to the mesh, and following the examples I need to do something like this

Code: Select all

this->setMaterialTexture(0, SceneManager->getVideoDriver()->getTexture("data\\Planetgas0-cl.bmp")); 
// set diffuse texture
this->setMaterialFlag(video::EMF_LIGHTING, true); // enable dynamic lighting
this->getMaterial(0).Shininess = 20.0f; 
However, when I get to this->getMaterial(0).Shininess = 20.0f, the program crashes, and the debugger spits out:

Code: Select all

First-chance exception at 0x00409e99 in GameEngine.exe: 0xC0000005: Access violation writing location 0x00000014.
Unhandled exception at 0x00409e99 in GameEngine.exe: 0xC0000005: Access violation writing location 0x00000014.
Does this have to do with the fact I am creating a custom scene node?
Could someone please give me some direction?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Maybe you didn't override getMaterial, hence it returns a Nullpointer.
kohansey
Posts: 14
Joined: Tue Apr 01, 2008 3:18 am

Post by kohansey »

yes, that is correct. I didn't override the getMaterial function. Is this a requirement to get textures to work for custom scene nodes? Is the scene node responsible for handling the materials of the meshes? How would one go about doing this? Is there anything else that I would need to override?

I took a look at AnimatedMeshSceneNode, and it uses a core::array of SMaterials. I am confused about this, I thought that the Material was specific to the mesh not the node, how does the node know which material to render for any given mesh?
kohansey
Posts: 14
Joined: Tue Apr 01, 2008 3:18 am

Post by kohansey »

I guess the real question is, what does setMaterialTexture do if my custom scene node contains the SMaterial?
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Look at the code and see what it does...

Code: Select all

		void setMaterialTexture(u32 textureLayer, video::ITexture* texture)
		{
			if (textureLayer >= video::MATERIAL_MAX_TEXTURES)
				return;

			for (u32 i=0; i<getMaterialCount(); ++i)
				getMaterial(i).setTexture(textureLayer, texture);
		}
What happens if getMaterialCount() returns 0 or getMaterial() doesn't return the material?

Travis
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

A custom scene node must override the getMaterial method. Due to some (bad?) design decisions from the past, the method is not pure virtual, so the compiler doesn't require you to override it. But in that case a casted Null will be returned.
Post Reply