[DX10] Problem with D3DX10CreateMesh()

Started by
4 comments, last by brekehan 15 years, 8 months ago
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?
Advertisement
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.
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?
I've got the same problem, if I figure it out I'll tell you.
This is your life, and it's ending one minute at a time. - Fight club
@EmptyVoid: Thanks, I'll do the same.
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]

This topic is closed to new replies.

Advertisement