Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

kevlur

meshes and direct3d9

This topic is 5396 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

Hi, im trying to load meshes .x with direct3d9, im using a class to do it, take from davesprogramming.com
class Mesh
{
public:
	void Draw(void);					
	bool Load(char *filename);					
private:
	LPD3DXBUFFER			pD3DXMtrlBuffer;	
	LPD3DXBUFFER			pAdjacencyBuffer;
	LPD3DXMESH				g_pMesh;			
	D3DMATERIAL9*			g_pMeshMaterials;	
	LPDIRECT3DTEXTURE9*		g_pMeshTextures;	
	DWORD					g_dwNumMaterials;	
};
the two functions are so defined
void Mesh::Draw(void)
{
    
	for( DWORD i=0; i<g_dwNumMaterials; i++ )
	{
		
	g_d3d_device->SetMaterial( &g_pMeshMaterials[i] );		g_d3d_device->SetTexture( 0, g_pMeshTextures[i] );	
		
		
	g_pMesh->DrawSubset( i );						
	}
}


bool Mesh::Load(char *filename)
{
        g_pMesh			= NULL;
        g_pMeshMaterials	= NULL; 
	g_pMeshTextures		= NULL; 
	g_dwNumMaterials	= 0;	
	if( FAILED( D3DXLoadMeshFromX( filename,	D3DXMESH_VB_WRITEONLY|D3DXMESH_MANAGED,							          NULL,						      &pD3DXMtrlBuffer,
			      &pAdjacencyBuffer,				              &g_dwNumMaterials,					                &g_pMesh ) ) )
    {
		return false;	    
    }

        D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();

g_pMeshMaterials = new D3DMATERIAL9[g_dwNumMaterials];			
g_pMeshTextures  = new LPDIRECT3DTEXTURE9[g_dwNumMaterials];	    for( DWORD i=0; i<g_dwNumMaterials; i++ )
	    {
        g_pMeshMaterials[i] = d3dxMaterials[i].MatD3D;

				
		g_pMeshMaterials[i].Power = 10;		        if( FAILED( D3DXCreateTextureFromFile( g_d3d_device, 
                  d3dxMaterials[i].pTextureFilename, 
                                &g_pMeshTextures[i] ) ) )
        {
			
            g_pMeshTextures[i] = NULL;
        }
    }

        pD3DXMtrlBuffer->Release();
	return true;
}
the problem is that the function
	if( FAILED( D3DXLoadMeshFromX( filename,	D3DXMESH_VB_WRITEONLY|D3DXMESH_MANAGED,							          NULL,						      &pD3DXMtrlBuffer,
			      &pAdjacencyBuffer,				              &g_dwNumMaterials,					                &g_pMesh ) ) )
    {
		return false;	    
    }
always returns false and i dont understand why... could someone tell me why Thanks Kev

Share this post


Link to post
Share on other sites
Advertisement
Use DXTrace to find out what the Error is

#include <dxerr9.h>

#pragma comment (lib, "dxerr9.lib") //Or add it to your project settings if you''re that way inclined

then go
HRESULT hr;
if (FAILED(hr = DXSomeFunction()))
{
DXTrace(__FILE__, __LINE__, hr, "DXSomeFunction failed", false);
return false;
}

look it up in the SDK, it''s worth it''s weight in small coconuts

Share this post


Link to post
Share on other sites
Make sure you''re using the Debug Runtime (Control Panel->DirectX. Then go to the Direct3D tab). Crank up the Debug Output Level. With that done, check to see what the debug spew says (it should tell you why the function failed).

neneboricua

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!