Original Post
Hello, I am following a tutorial, specifically the one about vertex and index buffers. I think that I understand what they are: vertex buffers hold vertices and index buffers provide a way to reuse the triangles formed by the vertices. The problem that I'm having is that a box that I exported was extremely skewed. I wrote an exporter for my modeling program to export just the geometry, and I am 100% sure that is is giving me the right data, but it isn't rendering properly. The format is simple - vertex count, then x/y/z of all vertices, then face count followed by the face x/y/z. I've debugged the loading section just to make sure. Basically, I have this vertex structure: Where gt is my actual vertices once loaded in to be used for my vertex buffer, and gti is the indices to be used in the index buffer. Here is where I create the buffers (see the source at the tutorial): And rendering: Now, I am guessing that a face is just a fancy name for a triangle. Perhaps this is where I am going wrong, but I'm not sure. The exports for the face x/y/z of faces of a simple box look like ...I figured these numbers to be the correct indexes for the buffer. Am I wrong in this assumption? If not, then how do I get the correct indices? Pardon me if I sound like a complete noob to 3d programming; I am. Thanks for your help. [Edited by - Kuraitou on July 13, 2008 1:03:49 PM]
struct CUSTOMVERTEX
{
float x, y, z; // Position in 3d space
DWORD color; // Color
};
CUSTOMVERTEX *gt = NULL;
USHORT *gti = NULL;
m_VB.CreateBuffer(pDevice, vertCount, D3DFVF_XYZ | D3DFVF_DIFFUSE, sizeof(CUSTOMVERTEX));
m_VB.SetData(vertCount, gt);
m_IB.CreateBuffer(pDevice, faceCount * 3, D3DFMT_INDEX16);
m_IB.SetData(faceCount * 3, gti);
m_VB.SetIndexBuffer(&m_IB);
pDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
pDevice->BeginScene();
pDevice->SetTransform( D3DTS_WORLD, m_transform.GetTransform() );
vb.Render( pDevice, faceCount, D3DPT_TRIANGLELIST );
pDevice->EndScene();
pDevice->Present(0, 0, 0, 0);
[1,3,4]
[4,2,1]
[5,6,8]
[8,7,5]
[1,2,6]
[6,5,1]
[2,4,8]
[8,6,2]
[4,3,7]
[7,8,4]
[3,1,5]
[5,7,3]