Archived

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

shakazed

Sending LPDIRECT3DDEVICE9 to a class func.

Recommended Posts

Hi! I have a class in my project that takes care of loading and rendering .x files. The problem is that after I pass my LPDIRECT3DDEVICE interface ptr to the first load function it collapses, with that I mean that I can´t use the ptr cuz then I get an error. The func. looks like this.
HRESULT CXModel::LoadXFile(char* p_strPathModelname, char* p_strPathTexturename, LPDIRECT3DDEVICE9 lpD3DDev9)
{
	LPD3DXBUFFER lpD3DXMtrlBuffer;

	if(FAILED(D3DXLoadMeshFromX(p_strPathModelname, D3DXMESH_SYSTEMMEM, lpD3DDev9, NULL,
		&lpD3DXMtrlBuffer, NULL, &lNumMtrls, &lpD3DXMesh)))
	{
		MessageBox(NULL, "Failed to load .x file", "DX_02.exe", MB_OK);
	}

	d3dxMtrl = (D3DXMATERIAL*)lpD3DXMtrlBuffer->GetBufferPointer();
	d3dMaterials = new D3DMATERIAL9[lNumMtrls];
	lpD3DTexture = new LPDIRECT3DTEXTURE9[lNumMtrls];

	for(unsigned long i = 0; i<lNumMtrls; i++)
	{
		d3dMaterials[i] = d3dxMtrl[i].MatD3D;
		d3dMaterials[i].Ambient = d3dMaterials[i].Diffuse;

		if(FAILED(D3DXCreateTextureFromFile(lpD3DDev9, p_strPathTexturename,
			&lpD3DTexture[i])))
		{
			MessageBox(NULL, "Failed to load texture", "DX_02.exe", MB_OK);
		}
		
	}

	lpD3DXMtrlBuffer->Release();
	
	return S_OK;
}
And this is how I call the function, passing my LPDIRECT3DDEVICE ptr.
CXModel cMap;
cMap.RenderXFile(lpD3DDev9);
Oh, the class is in a seperate file.
Bad Monkey Productions

Share this post


Link to post
Share on other sites