Jump to content
  • Advertisement
Sign in to follow this  

Simple Custom Model Format (solved)

This topic is 3777 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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:
	float x, y, z; // Position in 3d space
	DWORD color;   // Color


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):
    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);

And rendering:
	pDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

    pDevice->SetTransform( D3DTS_WORLD, m_transform.GetTransform() );
	vb.Render( pDevice, faceCount, D3DPT_TRIANGLELIST );

	pDevice->Present(0, 0, 0, 0);

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]

Share this post

Link to post
Share on other sites
I suspect your indices, Kuraitou. It appears that each of the face indices should be reduced by 1.

That is, [1,3,4] should be [0,2,3], [4,2,1] should be [3,1,0], etc.

Remember, indexing is zero-based! [smile]

By the way, the term "face" is used because an object face isn't always a triangle. It could be a quad, for instance.

Share this post

Link to post
Share on other sites
That was the problem, apparently. I do feel quite stupid for not realizing it earlier, many thanks and ++ratings.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!