Hullo again all, I attached an image below of what I'm rendering (an improvement since last time).
The top-left image is rendering with a D3DFILL_SOLID option.
The top-right is with a D3DFILL_WIREFRAME option. (Note, for the wireframe, I turned culling off).
The bottom-centre ship is what the mesh viewer included with the DirectX SDK renders (slightly better quality than mine, I'll admit)
As you can see, the guns should not be being rendered behind the ship, and nor should that cylinder be showing through the top of my ship. I just can't seem to figure out why...
My Render States include:
Code:
D3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
D3DDevice->SetRenderState(D3DRS_ZENABLE, TRUE);
D3DDevice->SetRenderState(D3DRS_LIGHTING, TRUE);
D3DDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
D3DDevice->SetRenderState(D3DRS_NORMALIZENORMALS, TRUE);
D3DDevice->SetRenderState(D3DRS_AMBIENT, 0x00AAAAAA);
I don't think the following code is the issue, but I'll post it anyways:
Code:
//LOADING A MESH OBJECT FROM A .X FILE
bool cMesh::MeshCreateObject(IDirect3DDevice9* D3DDevice, char* FileName)
{
ID3DXMesh* TempMesh = NULL;
ID3DXBuffer* TempMeshMaterialBuffer = NULL;
D3DXMATERIAL* TempMeshMaterials = NULL;
unsigned long X = 0;
MeshD3DDevice = D3DDevice;
if(FAILED(D3DXLoadMeshFromX(FileName, D3DXMESH_SYSTEMMEM, D3DDevice, NULL, &TempMeshMaterialBuffer, NULL, &MeshNumMaterials, &TempMesh)))
return false;
TempMeshMaterials = (D3DXMATERIAL*)TempMeshMaterialBuffer->GetBufferPointer();
MeshMaterials = new D3DMATERIAL9[MeshNumMaterials];
MeshTextures = new IDirect3DTexture9*[MeshNumMaterials];
for(X = 0; X < MeshNumMaterials; X++)
{
MeshMaterials[X] = TempMeshMaterials[X].MatD3D;
MeshMaterials[X].Ambient = MeshMaterials[X].Diffuse;
if(FAILED(D3DXCreateTextureFromFile(
D3DDevice,
TempMeshMaterials[X].pTextureFilename,
&MeshTextures[X])))
{
MeshTextures[X] = NULL;
}
}
SafeRelease(TempMeshMaterialBuffer);
TempMesh->CloneMeshFVF(D3DXMESH_MANAGED, MESH_D3DFVF_CUSTOMVERTEX, MeshD3DDevice, &Mesh);
SafeRelease(TempMesh);
D3DXComputeNormals(Mesh, NULL);
return true;
}
//RENDERING MY MESH
unsigned long cMesh::MeshRender(void)
{
unsigned long X;
if(Mesh != NULL)
{
for(X = 0; X < MeshNumMaterials; X++)
{
MeshD3DDevice->SetMaterial(&MeshMaterials[X]);
MeshD3DDevice->SetTexture(0, MeshTextures[X]);
Mesh->DrawSubset(X);
}
return Mesh->GetNumFaces();
}
return 0;
}
Umm...yeah, I don't know what else would be relevant to this problem. I don't get why the Z-Buffer isn't handling the rendering...
Any changes to culling fuddles it up some more, but the Z-Issue is still there. Are there any ideas about what's going on?
On another topic
I was hoping somebody could explain the differences between the Attenuation0, Attenuation1, and Attenuation2 properties of a D3DLIGHT9 object. MSDN gives the same definition for each, and then explains that they each behave differently, without saying how. It has something to do with how the light dies off as it gets further from the source, but I was hoping somebody knew a bit more about them...
Thanks for givin' this a read. Ideas and comments are always appreciated.