tags:

views:

44

answers:

2

I wrote a simple program to load a directX .x mesh file. My loaded image is displayed like this.

But the one which the MeshViewer shows is like this.

What should be done to get the 3D look? Which call in the DirectX library should I make?

+1  A: 

Looks like you haven't set any light.

You have to load the materials defined in the mesh, and set at least one light.

Once you've set a light, the rendering code using the fixed pipeline in DirectX 9 looks like this:

// NumMaterials and ShipMaterialshave already been loaded with the call to D3DXLoadMeshFromX
D3DXMATERIAL* ShipMats = (D3DXMATERIAL*) ShipMaterials->GetBufferPointer();
device->SetTexture(0, NULL); // assume a mesh with no texture
for (DWORD i = 0; i < NumMaterials; ++i) 
{
    device->SetMaterial(&ShipMats[i].MatD3D);
    this->pShipMesh->DrawSubset(i);
}

If you still don't see anything, set a material you've defined yourself.

Samuel_xL
I set some lighting like [this](http://pastebin.com/xj0BpGwn). but still i get the same image!
bdhar
have you set a material ? To "see" the lighting, you need both a light and a material. Btw I've edited my answer.
Samuel_xL
[It](http://pastebin.com/bGpPkdf8) was included in the code :(. Still no effect!!
bdhar
+1  A: 

Are you loading the same file into the viewer as into your own application? 'Cause it actually looks like you don't have any normals in the mesh. If your using the same file as the viewer, they should be in the mesh file though.

Other than that, your lighting is incredibly bright (all values at 1.0), I would set the diffuse values to 0.0 and try setting the ambient to 0.5 red. Then at least you can tell if your light is working.

JonoRR
Thanks. The problem was with the normals. The call [D3DXComputeNormals](http://msdn.microsoft.com/en-us/library/bb172742%28VS.85%29.aspx) helped me
bdhar