Sign in to follow this  
Bangladesh

[DX10] Problem with D3DX10CreateMesh()

Recommended Posts

Bangladesh    122
I'm trying to create a D3DX10Mesh-object but can't get the thing to draw. Checking all HRESULTS (removed for easier reading) but no errors are thrown. The code I use for creating this object is shown below.
// Create vertex buffer
    VertexPosTexStruct vertices[] =
    {
		{ D3DXVECTOR3(0.0f, 1.0f, 0.0f), D3DXVECTOR3(0.0f, 0.0f, -1.0f), D3DXVECTOR2(0.5f, 0.0f) },
		{ D3DXVECTOR3(1.0f, -0.5f, 0.0f), D3DXVECTOR3(0.0f, 0.0f, -1.0f), D3DXVECTOR2(1.0f, 1.0f) },
		{ D3DXVECTOR3(-1.0f, -0.5f, 0.0f),  D3DXVECTOR3(0.0f, 0.0f, -1.0f), D3DXVECTOR2(0.0f, 1.0f) },
    };

	// Calculate the number of vertices in the array
	UINT numVertices = sizeof(vertices) / sizeof(VertexPosTexStruct);
	UINT numStride = sizeof(VertexPosTexStruct);
	UINT numOffset = 0;

        // Create inputlayout
	D3D10_INPUT_ELEMENT_DESC layout[] =
    {
        { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
		{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 },
		{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0 },
    };

	UINT numElements = sizeof(layout) / sizeof(D3D10_INPUT_ELEMENT_DESC);

	// Create the mesh-object member
	D3DX10CreateMesh( m_pDevice,
						  layout,
						  numElements,
						  "POSITION",
						  numVertices,
						  numVertices / 3,
						  D3DX10_MESH_32_BIT,
						  &m_pMesh );


	// Try to set the data into the object
	m_pMesh->SetVertexData(0, vertices);

	// Commit changes
	m_pMesh->CommitToDevice();





// When Drawing I use this...
for(UINT p=0; p < techniqueDescription.Passes; ++p)
    {
        pShaderTechnique->GetPassByIndex(p)->Apply(0);
	m_pMesh->DrawSubset(0);
    }


This does not work. Does anybody have a working snippet they know work, I can use?

Share this post


Link to post
Share on other sites
ET3D    810
A couple of suggestions:

Try PIX. You'll be able to see if anything is being drawn, and how vertices are transformed (if they are).

Try this code without the mesh. Create a vertex buffer and draw it. That'd show you if the problem is with the mesh or the data.

Share this post


Link to post
Share on other sites
Bangladesh    122
I've tried it with the same data, but in a normal vertexbuffer and it works fine, so it's probably a matter of how the mesh is created or user.

Do I have to set anything in the mesh manually before rendering besides what's already there in the example? Is there a tut of this somewhere?

Share this post


Link to post
Share on other sites
brekehan    101
I am just guessing, but don't you need an index buffer to tell it what vertices to draw and in what order?

I also do not see where you bound the input layout using IASetInputLayout()



[Edited by - brekehan on August 26, 2008 5:06:07 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this