Sign in to follow this  
Kapoef

Loading x files using D3DXLoadMeshFromX [Solved]

Recommended Posts

Kapoef    115
Hi Can some1 plz explain to me how to do the following: - Loading a *.fx file from the D3DXLoadMeshFromX. - and applying the effects K, i'm able to load the mesh with textures and materials using

if(FAILED(D3DXLoadMeshFromX(dir,D3DXMESH_SYSTEMMEM,
                            CGraphics::GetDevice(), NULL,
                            &materialBuffer,&effectBuffer, &m_numMaterials,
                            &m_mesh )))
	return false;





For a start I loaded an example mesh from the Directx SDK, I loaded the "DwarfWithEffectInstance.x". Now i know this model uses "reflect.fx" and "specular.fx" cuz if i remove these fx files then the directx X file viewer displays the dwarf differently. Now the question is, how do I use the returned effectBuffer parameter to use the specified effects???????? I'm still new to using fx files and what not. And i have never used pixel shading nor vertex shading. Any help or guidelines will be greatly appreciated. Thx [Edited by - Kapoef on March 18, 2010 7:22:32 PM]

Share this post


Link to post
Share on other sites
Kapoef    115
I know the effectBuffer that is returned hold the directories for the fx files but when i load them the program crashes.

this is what i'm doing:



if(FAILED(D3DXLoadMeshFromX(dir, D3DXMESH_SYSTEMMEM,
CGraphics::GetDevice(), NULL,
&materialBuffer,&effectBuffer, &m_numMaterials,
&m_mesh )))
return false;

D3DXEFFECTINSTANCE* d3dxEffects=(D3DXEFFECTINSTANCE*)effectBuffer->GetBufferPointer();

std::string tmp=d3dxEffects->pEffectFilename;
if(tmp)
{
m_Effects = new CGfxEffects(CGraphics::GetDevice());
if(m_Effects->LoadEffect(tmp))
m_hasEffects=true;
}

....
....

bool CGfxEffects::LoadEffect(std::string dir)
{
m_dir = dir;

m_Flags = D3DXSHADER_DEBUG | D3DXSHADER_SKIPOPTIMIZATION;

HRESULT hr = D3DXCreateEffectFromFile(m_pDevice,m_Dir.c_str(),
m_pD3DDefines,m_pD3DInclude,
m_Flags,m_pD3DPool,
&m_pEffect,
&m_pErrors);

if (hr == D3D_OK)
{
m_Created = true;
return true;
}
if (hr == D3DERR_INVALIDCALL)
{
MessageBox(NULL,"D3DERR_INVALIDCALL",
"ERROR",MB_OK);
return false;
}
/*
* This is where i get an error. I keep getting the INVALIDDATA error
*/

if (hr == D3DXERR_INVALIDDATA)
{
MessageBox(NULL,"D3DXERR_INVALIDDATA",
"ERROR",MB_OK);
return false;
}
if (hr == E_OUTOFMEMORY)
{
MessageBox(NULL,"E_OUTOFMEMORY","ERROR",MB_OK);
return false;
}

return true;
}


Share this post


Link to post
Share on other sites
Evil Steve    2017
Quote:
Original post by Kapoef
I know the effectBuffer that is returned hold the directories for the fx files but when i load them the program crashes.
Then you need to fix the crash. What does your debugger tell you the problem is?

EDIT: If you get a D3D function failing, what do the debug runtimes tell you the problem is? Are you looking in the correct place for the .fx files (I seem to recall there's no directory information in the filename, so you'll need to make sure they're in the same directory as your app, or search the SDK media directory like the X file viewer does).

Share this post


Link to post
Share on other sites
Kapoef    115
k i added this



if (!m_pD3DEffect)
{
LPCTSTR buff = (LPCTSTR)m_pD3DCompileErrors->GetBufferPointer();
MessageBox(NULL,buff,"Compiler Errors",MB_OK);
//return false;
}





just after the



if (hr == E_OUTOFMEMORY)
{
MessageBox(NULL,"E_OUTOFMEMORY","ERROR",MB_OK);
//return false;
}




and i removed all the return false; statements and got this :

d:\game_project\stable\qeap\Data\reflect.fx(224,17): warning X3571: pow(f, e) will not work for negative f, use abs(f) or conditionally handle negative values if you expect them
d:\game_project\stable\qeap\Data\reflect.fx(204,14): error X4505: maximum temp register index exceeded
d:\game_project\stable\qeap\Data\reflect.fx(204,14): error X4505: maximum temp register index exceeded
d:\game_project\stable\qeap\Data\reflect.fx(204,14): error X4505: maximum temp register index exceeded
d:\game_project\stable\qeap\Data\reflect.fx(204,14): error X4505: maximum temp register index exceeded
d:\game_project\stable\qeap\Data\reflect.fx(204,14): error X4505: maximum temp register index exceeded
d:\game_project\stable\qeap\Data\reflect.fx(204,14): error X4505: maximum temp register index exceeded
ID3DXEffectCompiler: Compilation failed

I dont know if this helps, i dont even know how to interpret this. The only thing that makes sence to me is the "ID3DXEffectCompiler: Compilation failed" but i dont understand why i get this error cuz the DirectX x file viewer displays the correct model.

Share this post


Link to post
Share on other sites
Kapoef    115
I got this working, YAY!!!!

if anybody has the same problems as i had check this page

http://www.riemers.net/eng/Tutorials/DirectX/Csharp/series3.php

Its in C# but HLSL is HLSL...

Share this post


Link to post
Share on other sites

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