Sign in to follow this  

Loading .fx parameters from an .x file

This topic is 4856 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all, I'm writing a simple D3D9 app to load a mesh from an .x file that contains .fx parameters for some or all materials. Currently, the ID3DXEffect is correctly being instantiated, and the .fx parameters are correctly loaded from the attribute table, however, trying to set the shader paremeters stored in the mesh file is giving me greif. My code looks something like this:
for( DWORD i = 0; i < g_dwNumMaterials; i++ ) {

		g_pMeshMaterials[i] = d3dxMaterials[i].MatD3D;
		g_pMeshMaterials[i].Ambient = g_pMeshMaterials[i].Diffuse;

		g_pEffects[i] = NULL;
		if( d3dxEffects[i].pEffectFilename != NULL && lstrlen(d3dxEffects[i].pEffectFilename) > 0 )
		{
			if( FAILED( D3DXCreateEffectFromFile( g_pd3dDevice, d3dxEffects[i].pEffectFilename, NULL, NULL, 0, NULL,
				&g_pEffects[i], NULL ) ) )
			{
				abort();
			}

			for( DWORD j = 0; j < d3dxEffects[i].NumDefaults; j++ ) 
			{	
				D3DXHANDLE hEffectName = g_pEffects[i]->GetParameterByName( NULL, d3dxEffects[i].pDefaults[j].pParamName );
				g_pEffects[i]->SetValue( hEffectName, d3dxEffects[i].pDefaults[j].pValue, d3dxEffects[i].pDefaults[j].NumBytes );
			}
		}

// and some more code for loading textures (which works)

Debugging reveals that GetParameterByName is not returning a valid handle pointer, though I can verify the input parameter name is a valid string which occurs in the top level of the .fx file. Anyone know why this isn't working or what the proper method for dealing with embedded shader materials in .x files is? Thanks!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
What do you mean by "not returning a valid handle" ?
GetParameterByName will return a NULL handle when it fails (only non valid value), any other value means it works.
Be carefull of your debugger saying its a , it is not a relevant information for handles.
Try using the handle you received to set some values (SetXXX)instead and check the return HRESULT code.
Hope that Helps

Share this post


Link to post
Share on other sites
Interesting that handles are not valid char pointers, how does the framework differentiate between handles and strings then? a try/catch to check for dereferencing invalid pointers?

Also I've been digging around in the modelview source that shipped with the sdk, looks like my approach is a bit naive...also discovered the reason it wasn't working is because you can't set a texture to a string...had to load the texture first and Setxxx with the pointer to the texture object. Either way the D3DXCreateEffectInstance function in util.cpp of modelview provided some insight, hope that helps people who are trying to do the same thing.

Share this post


Link to post
Share on other sites

This topic is 4856 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this