Original Post
My app currently can load in D3DxMeshes. The program works fine when I set my custom vertex to the following:
typedef struct
{
D3DXVECTOR3 position; // The 3D position for the vertex
D3DXVECTOR3 normal; // The 3D position for the
} CUSTOMVERTEX ;
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL)
I copy the mesh, loaded in by the normal d3D way, into a mesh with my own vertex format. So I can pull out vertex details as I need them.
g_pMesh[iMeshCount]->CloneMeshFVF(D3DXMESH_SYSTEMMEM, D3DFVF_CUSTOMVERTEX, g_pd3dDevice[iMeshCount], &g_pMesh[iMeshCount]);
I then get a pointer to the vertex buffer, to give me acces to the values of each vertex (xyz, normals, uv).
g_pMesh[iMeshCount]->LockVertexBuffer(D3DLOCK_READONLY, (LPVOID*)&pVertexMesh[iMeshCount]);
g_pMesh[iMeshCount]->UnlockVertexBuffer();
Further in the code, I am copying the vertex values of the main mesh using the pointers provided by LockVertexBuffer:
for (DWORD index = 0; index <= iNumVerts-1; index++) {
pVertexMeshClone[index].x = pVertexMesh[0][index].x;
pVertexMeshClone[index].y = pVertexMesh[0][index].y;
pVertexMeshClone[index].z = pVertexMesh[0][index].z;
g_pMeshClone->LockVertexBuffer(D3DLOCK_DISCARD, (LPVOID*)&pVertexMeshClone);
g_pMeshClone->UnlockVertexBuffer();
The d3D meshclone was created earlier in the code. When i use the above CUSTOMVERTEX, the program works fine. I know this as I am printing the vertex of pVertexMesh (etc.) to the screen. However, when I declare my customvertex like this:
typedef struct
{
D3DXVECTOR3 position; // The 3D position for the vertex
D3DXVECTOR3 normal; // The 3D position for the vertex
float u, v; // The texture coordinates
}
} CUSTOMVERTEX ;
// Our custom FVF, which describes our custom vertex structure
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX0)
the program crashes on pVertexMeshClone[index].x = pVertexMesh[0][index].x; I later relasied that I hadn't been allocating memory for the vertex buffer, so I added the following code:
iNumVerts = g_pMeshClone->GetNumVertices();
pVertexMeshClone = new CUSTOMVERTEX[iNumVerts];
ZeroMemory(&pVertexMeshClone, sizeof(CUSTOMVERTEX) * iNumVerts);
I do this in a similar way for the main mesh. Now when I run the program, it just exits when I try to load my mesh (from a menu). It doesn't even tell me if it's crashing.. Can someone help, please. Thanks