Jump to content
  • Advertisement
Sign in to follow this  
bijan311

[DirectX 10]Problem with ID3DX10Mesh

This topic is 2443 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

When I try to create a grid using ID3DX10Mesh, it turns out to be some sort of pyramid, like this
4e74fc45ba4e2.jpg,
but when I use buffers, it works just fine.
Here is my code.



void GameStart()
{
D3D10_INPUT_ELEMENT_DESC layout[] = {
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
{"COLOR", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0},
};

g_pGame->CreateRasterizer(D3D10_FILL_WIREFRAME, D3D10_CULL_NONE, true);

int numElements = (sizeof(layout) / sizeof(layout[0]));
//Declare the vertices
VertexStruct vertices[NUM_VERTSX * NUM_VERTSY];

for(int z = 0; z < NUM_VERTSY; ++z)
{
for(int x = 0; x < NUM_VERTSX; ++x)
{
vertices[x + z * NUM_VERTSX].Pos.x = (float)(x * CELL_WIDTH);
vertices[x + z * NUM_VERTSX].Pos.z = (float)(z * CELL_HEIGHT);

//Have the height be randomly generated
vertices[x + z * NUM_VERTSX].Pos.y = 0.0f;

vertices[x + z * NUM_VERTSX].Color = D3DXVECTOR4(1.0f, 0.0f, 0.0f, 0.0f);
}
}
//Find out how many vertices are in the array
int iNumVertices = sizeof(vertices) / sizeof(VertexStruct);

//Declare the indices
DWORD indices[NUM_VERTSX * NUM_VERTSY * 6];
//current int counter
int curIndex = 0;

for (int z=0; z < NUM_ROWS; z++)
{
for (int x=0; x < NUM_COLS; x++)
{
// The current vertex to build off of
int curVertex = x + (z * NUM_VERTSX);

// Create the indices for the first triangle
indices[curIndex] = curVertex;
indices[curIndex+1] = curVertex + NUM_VERTSX;
indices[curIndex+2] = curVertex + 1;

// Create the indices for the second triangle
indices[curIndex+3] = curVertex + 1;
indices[curIndex+4] = curVertex + NUM_VERTSX;
indices[curIndex+5] = curVertex + NUM_VERTSX + 1;

// increment curIndex by the number of vertices for the two triangles
curIndex += 6;
}
}

int numIndices = sizeof(indices) / sizeof(DWORD);

ID3D10Blob* pError = NULL;

D3DX10CreateEffectFromFile(TEXT("Effect.fx"), NULL, NULL, "fx_4_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, g_pGame->GetDevice(),
NULL, NULL, &g_pEffect, &pError, NULL);

LPVOID l_pError = NULL;
if(pError)
l_pError = pError->GetBufferPointer();

//Create Input layout
ID3D10InputLayout* pLayout;
D3D10_PASS_DESC passDesc;
g_pEffect->GetTechniqueByName("Render")->GetPassByIndex(0)->GetDesc(&passDesc);
g_pGame->GetDevice()->CreateInputLayout(layout, numElements, passDesc.pIAInputSignature, passDesc.IAInputSignatureSize, &pLayout);

//Create a temporary mesh object
ID3DX10Mesh* pTempMesh;
HRESULT hr = D3DX10CreateMesh(g_pGame->GetDevice(), layout, numElements, "POSITION", iNumVertices,
(numIndices / 3), D3DX10_MESH_32_BIT, &pTempMesh);

//Set the vertices and indices to the mesh
hr = pTempMesh->SetVertexData(0, vertices);
hr = pTempMesh->SetIndexData(indices, numIndices);
hr = pTempMesh->CommitToDevice();

//Create the model object
g_pModel = new ModelObject(g_pGame->GetDevice(), pLayout, pTempMesh, g_pEffect->GetTechniqueByName("Render"));

g_pGame->CreateEffectMatrices(g_pEffect);

//Set the Eye and At vector for the camera
g_vEye = D3DXVECTOR3(0.0f, 175.0f, -300.0f);
g_vAt = D3DXVECTOR3(0.0f, 0.0f, 0.0f);

g_pGame->SetCamera(g_vEye, g_vAt);
}

void ModelObject::Draw()
{
//Make sure the mesh is valid
if(!m_pMesh)
return;

m_pDevice->IASetInputLayout(m_pInputLayout);

D3D10_TECHNIQUE_DESC TechniqueDesc;
m_pTechnique->GetDesc(&TechniqueDesc);

for(UINT p = 0; p < TechniqueDesc.Passes; ++p)
{
m_pTechnique->GetPassByIndex(p)->Apply(0);

//Draw the mesh
m_pMesh->DrawSubset(0);
}
}




Thank you

Share this post


Link to post
Share on other sites
Advertisement
Looks like your inputlayout isn't right. Should the color not be of type DXGI_FORMAT_R32G32B32A32_FLOAT ?

Share this post


Link to post
Share on other sites

Looks like your inputlayout isn't right. Should the color not be of type DXGI_FORMAT_R32G32B32A32_FLOAT ?


That was the problem, thanks.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!