Jump to content
  • Advertisement
Sign in to follow this  
Mafioso

D3DXLoadMeshFromX

This topic is 2906 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, I'm trying to load X file with c++ 2 days. Code compiles and runs, but model doesn't show on the screen, only background color :( Can you help me with it? Or can you post the code, how to load X file? I tried to add light, but still the same :( Model that I'm loading have material.



ID3DXMesh* mesh1 = NULL; // in global section

// my graphics function

DWORD numberMaterials = NULL;
ID3DXBuffer* adjBuffer = NULL;
ID3DXBuffer* materialBuffer = NULL;
D3DXLoadMeshFromX("w.x",D3DXMESH_SYSTEMMEM, d3ddev,&adjBuffer,&materialBuffer,0,&numberMaterials,&mesh1);

// TEXTURES

std::vector<D3DMATERIAL9> meshMaterials(0);
std::vector<IDirect3DTexture9*> meshTextures(0);

if (materialBuffer != NULL && numberMaterials != NULL)
{
D3DXMATERIAL* materialsPointer = (D3DXMATERIAL*)materialBuffer->GetBufferPointer();

for (int i = 0; i < numberMaterials; i++)
{
materialsPointer.MatD3D.Ambient = materialsPointer.MatD3D.Diffuse;

meshMaterials.push_back(materialsPointer.MatD3D);

if(materialsPointer.pTextureFilename !=0)
{
IDirect3DTexture9* texture = NULL;
D3DXCreateTextureFromFile(d3ddev,materialsPointer.pTextureFilename,&texture);

meshTextures.push_back(texture);

}
else meshTextures.push_back(0);
}
}

d3ddev->SetRenderState(D3DRS_LIGHTING, FALSE); // turn off the 3D lighting
d3ddev->BeginScene();
d3ddev->Clear(0,0,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,255), 1.0f, 0);

D3DXMATRIX camera;

D3DXMatrixLookAtLH(&camera,
&D3DXVECTOR3 (4.0f, 4.0f, -13.0f),
&D3DXVECTOR3 (0.0f, 0.0f, 0.0f),
&D3DXVECTOR3 (0.0f, 1.0f, 0.0f));

d3ddev->SetTransform(D3DTS_VIEW, &camera);

D3DXMATRIX matProjection;
D3DXMatrixPerspectiveFovLH(&matProjection,
D3DXToRadian(45),
(FLOAT)SCREEN_WIDTH / (FLOAT)SCREEN_HEIGHT,
1.0f, // the near view-plane
100.0f); // the far view-plane

d3ddev->SetTransform(D3DTS_PROJECTION, &matProjection);

for (int i = 0; i< numberMaterials; i++ )
{
d3ddev->SetMaterial(&meshMaterials);
d3ddev->SetTexture(0,meshTextures);
mesh1->DrawSubset(i);
}

d3ddev->EndScene();
d3ddev->Present(NULL,NULL,NULL,NULL);








[Edited by - Mafioso on July 10, 2010 12:58:43 PM]

Share this post


Link to post
Share on other sites
Advertisement
Maybe the camera is inside the mesh so try changing this lines:

D3DXMatrixLookAtLH(&camera,
&D3DXVECTOR3 (0.0f, 0.0f, -100.0f),
&D3DXVECTOR3 (0.0f, 0.0f, 0.0f),
&D3DXVECTOR3 (0.0f, 1.0f, 0.0f));



And also this line:

D3DXMatrixPerspectiveFovLH(&matProjection,
D3DXToRadian(45),
(FLOAT)SCREEN_WIDTH / (FLOAT)SCREEN_HEIGHT,
1.0f, // the near view-plane
1000.0f);

Share this post


Link to post
Share on other sites
I GOT IT!!! WOW, finaly after 2 days I loaded and X file ! :D then i wrote to this forum, I saw the mistakes :D

Still the materials doesn't loaded, can anyone see whats wrong?

Share this post


Link to post
Share on other sites
First, you don't say what you changed (perhaps in the original code you posted) to get things to work. You may be asking about a problem with code you haven't posted.

Second, you should be looking for errors using the return values from your DirectX calls. DX functions give some indication of success or failure.

I.e., use the FAILED() and SUCCEEDED() macros with functions that return an HRESULT to see if something isn't working.

E.g., your D3DXCreateTextureFromFile call may be failing and you push_back(NULL) for your texture.

Tough love follows --> you're asking people to debug code that you haven't tried to debug yourself. Rather than "What's wrong?," try "How do I find out what's wrong?"
Quote:
I GOT IT!
Others may have the same problem that you had. So share the solution! [smile]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!