Use default material help

Started by
5 comments, last by KOzymandias 15 years, 4 months ago
Im trying to load effects in my material system, but the application runs through the materials and will return an error message for every material that does not have an effect. So basically I'm trying to get the app to use the default material if an effect is not specified. Somethign liek this
// Load the effect file.
	ID3DXBuffer *errorBuffer = NULL;
	HRESULT result = D3DXCreateEffectFromFile( g_engine->GetDevice(), script->GetStringData( "effect" ), NULL, NULL, 0, NULL, &m_effect, &errorBuffer );
	if( script->GetStringData( "effect" ) == NULL ) 
	{
	// No valid effect for this material.  Use the default.
            
	
}
	else
		if( result != D3D_OK ){
		const char *error = NULL;
	if( errorBuffer )
      error = (const char*)errorBuffer->GetBufferPointer();
	else
      error = "Error loading effect file.";
	MessageBox( NULL, error, "Error", MB_OK ); // Display any errors.
	} 
I left it blank because I really dont even know how to proceed. Any ideas?
Advertisement
You could just create a default fx and load it when none is specified. I'm probably missing something because I don't see the problem :
filename = script->GetStringData( "effect" );if(filename == NULL)    filename = "default.fx";ID3DXBuffer *errorBuffer = NULL;HRESULT result = D3DXCreateEffectFromFile( g_engine->GetDevice(), filename, NULL, NULL, 0, NULL, &m_effect, &errorBuffer );if( result != D3D_OK ){    const char *error = NULL;    if( errorBuffer )        error = (const char*)errorBuffer->GetBufferPointer();    else        error = "Error loading effect file.";    MessageBox( NULL, error, "Error", MB_OK ); // Display any errors.}
I guess that could work, i know that directx had a default material somewhere. Its what the directx viewer uses if you don't specify a material.
What kind of identifier would filename use, everything I use doesn't work. i'm started to get frustrated.

[Edited by - Njguy on November 23, 2008 12:36:24 PM]
never mind its char * filename

I feel like an idiot now. Thanks though
ok the good news is that, the scene loaded. The bad news is that it did not apply the effect. (Which is better than what I expected it to do). There are so many reasons for it not to apply , I do not really know where to start. Im surprised, that I didn't get an error message I haven't specified the effect constants. Is there a way for an application not automatically detect the effect file's constants and load them? Am I being clear?
You can assign default values to your parameters in the effect file itself. If you want to automatically set parameters like the WorldViewProj matrix, you can use semantics. Give your parameters a semantic, then in your app you read the parameters description (D3DXPARAMETER_DESC). It holds the parameter name, semantic, type, class, bytecount, etc. That should be enough to set common parameters.

You can also add annotations in your effects : annotations contain a default value, but it wont initialize the object. But you can read it back in your application so you know how to set the parameter.

PS: I would use a std::string for the filename, and filename.c_str() in functions that need a const char pointer;

This topic is closed to new replies.

Advertisement