I wrote a program to load an obj file in directx 9. All I do is read the vertex data and the index data from the file ( I did not read any texture or vertex normal data). Then I plug this data directly into the vertex and index buffers.
When I run the code, the objects are rendered, but they are not the correct shape. The mesh gets deformed. Here is my code -
D3DXCreateMeshFVF(
index_size, // NumFaces
vertex_size, // NumVertices
D3DXMESH_MANAGED, // Options
D3DFVF_XYZ, // FVF
Device, // The Device
&Mesh[id].MeshData); // The Mesh
VOID* pVertices;
// Copy the vertices into the buffer
Mesh[id].MeshData->LockVertexBuffer(D3DLOCK_DISCARD, (void**)&pVertices);
memcpy( pVertices, VertexData, vertex_size*sizeof(FLOAT)*3); // VertexData is the vertex data that I obtained form the obj file
// Unlock the vertex buffer
Mesh[id].MeshData->UnlockVertexBuffer();
// Prepare to copy the indices into the index buffer
VOID* IndexPtr;
// Lock the index buffer
Mesh[id].MeshData->LockIndexBuffer( 0, &IndexPtr );
// Check to make sure the index buffer can be locked
// Copy the indices into the buffer
memcpy( IndexPtr, IndexData, index_size*sizeof(WORD));// IndexData is the list of indices I obtained form he obj file.
// Unlock the buffer
Mesh[id].MeshData->UnlockIndexBuffer();
When I display a cube, it displays only half of it, and some of the faces are missing. I susupect it is some problem with the index buffer, but I don't know how to fix it.
I really need help. Thanks all.