Drawing a triangle on a x-file face

Started by
1 comment, last by adriano_usp 20 years, 7 months ago
Hi, OK, I wrote the next code to extract the vertex data from my x-file: #define Maxfaces 100 // I know my mesh has 100 faces D3DXVECTOR3 v1[Maxfaces], v2[Maxfaces], v3[Maxfaces]; . . . // Get the buffers pMesh->GetIndexBuffer(&pIB); pMesh->GetVertexBuffer(&pVB); // Get face and vertex count numFaces = pMesh->GetNumFaces(); numVertices = pMesh->GetNumVertices(); CUSTOMVERTEX *pVertices; WORD* pIndices; pMesh->LockIndexBuffer(0L, (VOID**)&pIndices); pMesh->LockVertexBuffer(D3DLOCK_DISCARD,(VOID**)&pVertices); for (DWORD face=0; faceUnlockVertexBuffer(); pMesh->UnlockIndexBuffer(); . . . I don''t have experience in D3D (normally I use OpenGL), so I thought to store the position data in 3 arrays (v1, v2 and v3). Please, I would like to have your opnions about a better way to make this. My question is very simple: How to draw the triangle (face) composed, for example, by v1[10], v2[10] and v3[10]? In OGL it is very easy to make this, but in DX the process seems be more complicated... Another question: Is it a good idea to lock/unlock buffer in the render process? Thanks for your attention... and patience
Advertisement
... any help?
in OGL triangles are usually drawn 1by1.. in DX we use these vertex&index buffers.

I guess you only want to draw some of the triangles in your mesh and not the whole mesh?

so..
!!! Use the same vertexbuffer you allready have. no point duplicating/extracting vertices from your mesh. they are allready in memory.

so..
1. create a second index buffer
2. fill this second index buffer with triangles you want to draw
3. call SetStreamSource(yourvertexbuffer)
4. call SetIndices(the second indexbuffer)
5. call DrawIndexedPrimitive

in DX it is very slow to render one triangle at time. use those buffers.. read this Terrain Tutorial
--------------------------------------------------------I'm not crazy, It's the TV that's crazy. Aren't you, TV?--------------------------------------------------------

This topic is closed to new replies.

Advertisement