Sign in to follow this  
thuong

how to replace DrawSubset function by DrawIndexedPrimitiveUP or DrawPrimitiveUP funct

Recommended Posts

thuong    100
hi all, I want try to change function use to render object load from X file. last time i use : DrawSubset now i want to use DrawIndexedPrimitiveUP or DrawPrimitiveUP to render mesh, following is my code: LPD3DXMESH pDrawMesh = (meshContainer->pSkinInfo) ? meshContainer->exSkinMesh: meshContainer->MeshData.pMesh; FLOAT* pVert; WORD * pInd; pDrawMesh->LockVertexBuffer(D3DLOCK_READONLY, (VOID**) &pVert); pDrawMesh->LockIndexBuffer(D3DLOCK_READONLY, (VOID**) &pInd); m_d3dDevice->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, pDrawMesh->GetNumVertices(), pDrawMesh->GetNumFaces(), &pInd, D3DFMT_INDEX16, &pVert, meshContainer->m_inumElementsPerVertex * sizeof(FLOAT)); pDrawMesh->UnlockIndexBuffer(); pDrawMesh->UnlockVertexBuffer(); but i can not render, i do not see anything on view. if i use DrawSubset to render object then i can see, anybody pls help me solve that. Thanks very much,

Share this post


Link to post
Share on other sites
MJP    19756
You don't use DrawPrimitiveUP or DrawIndexedPrimitiveUP when you have a vertex buffer and an index buffer. The whole point of those functions is for rendering when you don't have the data in a vertex buffer or index buffer, hence you provide a pointer to user memory. You need to instead something along the lines of this:


m_d3dDevice->SetStreamSource(0, pDrawMesh->GetVertexBuffer(), 0, pDrawMesh->GetNumBytesPerVertex());
m_d3dDevice->SetIndices(pDrawMesh->GetIndexBuffer());
m_d3dDevice->SetVertexDeclaration(pDrawMesh->GetDeclaration());
m_d3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, pDrawMesh->GetNumVertices(), 0, pDrawMesh->GetNumFaces());

Share this post


Link to post
Share on other sites
thuong    100
How to i can manager mesh's polygon, example: how i can render each mesh's polygon, i had try but it incorrect.

following is my code:

LPDIRECT3DVERTEXBUFFER9 pVB;
LPDIRECT3DINDEXBUFFER9 pIB;
LPDIRECT3DVERTEXBUFFER9 pVBRender;
LPDIRECT3DINDEXBUFFER9 pIBRender;
D3DVERTEXELEMENT9 * Declaration = new D3DVERTEXELEMENT9[4];
LPDIRECT3DVERTEXDECLARATION9 pDeclaration;
pDrawMesh->GetVertexBuffer(&pVB);
pDrawMesh->GetIndexBuffer(&pIB);
pDrawMesh->GetDeclaration(Declaration);
HRESULT hr = m_d3dDevice->CreateVertexDeclaration( Declaration, &pDeclaration );

m_d3dDevice->CreateVertexBuffer(3 * pDrawMesh->GetNumBytesPerVertex(),
D3DUSAGE_WRITEONLY, 0, D3DPOOL_MANAGED,
&pVBRender, NULL);

m_d3dDevice->CreateIndexBuffer(1 * 3 * sizeof(WORD),
D3DUSAGE_WRITEONLY,
D3DFMT_INDEX16, D3DPOOL_MANAGED,
&pIBRender, NULL);

FLOAT * pVert;
FLOAT * pVertRender;
WORD * pInd;
WORD * pIndRender;
pVB->Lock(0, 0, (VOID**) &pVert, 0);
pIB->Lock(0, 0, (VOID**) &pInd, 0);


for(int i = 0; i < pDrawMesh->GetNumFaces(); i++)
{
pVBRender->Lock(0, 0, (VOID**) &pVertRender, 0);
pIBRender->Lock(0, 0, (VOID**) &pIndRender, 0);
pIndRender[0] = pInd[i*3+0];
pIndRender[1] = pInd[i*3+1];
pIndRender[2] = pInd[i*3+2];

memcpy(pVertRender, pVert+pIndRender[0]*meshContainer->m_inumElementsPerVertex, pDrawMesh->GetNumBytesPerVertex());
memcpy(pVertRender+meshContainer->m_inumElementsPerVertex, pVert+pIndRender[1]*meshContainer->m_inumElementsPerVertex, pDrawMesh->GetNumBytesPerVertex());
memcpy(pVertRender+2*meshContainer->m_inumElementsPerVertex, pVert+pIndRender[2]*meshContainer->m_inumElementsPerVertex, pDrawMesh->GetNumBytesPerVertex());

pIBRender->Unlock();
pVBRender->Unlock();

m_d3dDevice->SetStreamSource(0, pVBRender, 0, pDrawMesh->GetNumBytesPerVertex());
m_d3dDevice->SetIndices(pIBRender);
m_d3dDevice->SetVertexDeclaration(pDeclaration);
m_d3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 3, 0, 1);
}

pVB->Unlock();
pIB->Unlock();

pVBRender->Release();
pIBRender->Release();
delete [] Declaration;

Thank you very much.

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