How to define a new material type in Irrlicht source?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
qez111
Posts: 54
Joined: Mon Apr 28, 2008 9:44 pm

How to define a new material type in Irrlicht source?

Post by qez111 »

I have created a new material and I would like to add it to the source library. I have added the material class to to the Cd3dmaterialrenderer.h
and I added a line in cd3d9driver.h:

Code: Select all

addAndDropMaterialRenderer(new CD3D9MaterialRenderer_MYNEWMATERIAL(pID3DDevice, this));
I also defined EMT_MYNEWMATERIAL in enum E_MATERIAL_TYPE in EMATERIALTYPES.H file. And in sBuiltInMaterialTypeNames in the same file, I added "MYNEWMATERIAL" to the last line just before '0'.

But my application crashes after making the above changes.

any other definitions required, or more code to be added, in order to use the new material from the library, just like using EMT_SOLID OR EMT_TRANSPARENT_ALPHA_CHANNEL?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Why do you need to add it to the core library? You can add an extrnal material renderer as well, without interfering with library code. The crash could also result from old object code in your project, which assumes different header files and hence a different memory layout. But a debugger would tell what happens.
qez111
Posts: 54
Joined: Mon Apr 28, 2008 9:44 pm

Post by qez111 »

I know I can keep it external, but i ran into some troubles when I tried using an external material with IrrWizard. The program crashes, so I thought I could add it to the the source to avoid the crash.
When using debugger, the program execution breaks at

pManager->getSceneManager()->drawAll();
in GamePlayState.cpp under update() function.

I hv basically defined the material in Init() in the GamePlayStateLevel01.cpp, and also setting the material type to node->setMaterialType((E_MATERIAL_TYPE)newMat);


I am actually using this material in a separate application (not using Irrwizard), and it works perfectly. So that means there should be some problem when using irrWizard.
qez111
Posts: 54
Joined: Mon Apr 28, 2008 9:44 pm

Post by qez111 »

There seems to be a problem with IrrWizard template itself. Even if i set the material to one of the default material types, such as EMT_TRANSPARENT_ALPHA_CHANNEL, the program crashes.
Saturn
Posts: 418
Joined: Mon Sep 25, 2006 5:58 pm

Post by Saturn »

No it is not breaking at pManager->getSceneManager()->drawAll(); unless either pManager or pManager->getSceneManager() are not pointers to valid instances of their respective classes.
If you can rule this out, then you have to tell use where inside drawAll the program is crashing. What is the complete call stack? (With symbols)
qez111
Posts: 54
Joined: Mon Apr 28, 2008 9:44 pm

Post by qez111 »

Just to update on the last problem that the program crashes even when setting the material type to one of the built-in ones (such as EMT_TRANSPARENT_ALPHA_CHANNEL), I actually compiled and checked in Visual Studio 2005, and it works perfectly. Previously I was using Visual Studio 2008. However, I am still getting a crash on using custom materials.

Saturn, I will check the stack and post it here.
Post Reply