   initialize index buffer of mesh
  Hello allI try to create a simple square using mesh. The square has 2 triangles and 4 vertex points. Bellow is my function that must create this mesh. However after executing it I don't receive what I expected. Can someone tell where is my mistake:void CD3DSimulationView::CreateMeshes(){unsigned short nNumFaces = 2;unsigned short nNumVertices = 4;//setup meshif(SUCCESS(D3DXCreateMeshFVF(nNumFaces, nNumVertices, D3DXMESH_VB_MANAGED, D3DFVF_XYZ,m_pd3dDevice, &m_pMesh)){//allocate vertex bufferCUSTOMVERTEX* pVertices;m_pMesh->LockVertexBuffer(D3DLOCK_DISCARD, (void**)&pVertices);//initialize vertex buffer // X Y ZpVertices[0].m_pVertices = D3DXVECTOR3( 2, -2, 0);pVertices[1].m_pVertices = D3DXVECTOR3(-2, -2, 0);pVertices[2].m_pVertices = D3DXVECTOR3(-2, 2, 0);pVertices[3].m_pVertices = D3DXVECTOR3( 2, 2, 0);m_pMesh->UnlockVertexBuffer();//allocate and initialize index bufferUINT16 *pIB = NULL;m_pMesh->LockIndexBuffer(0, (void**)&pIB);pIB[0] = 0;pIB[1] = 1;pIB[2] = 2;pIB[3] = 0;pIB[4] = 3;pIB[5] = 2;m_pMesh->UnlockIndexBuffer();}}best regardsKamen[Edited by - f1engineer on August 21, 2007 7:50:07 AM]
Quote:Original post by f1engineerCan someone tell where is my mistake1. Not using [ source ] tags2. Not checking you return values3. Not using the debug runtimes, maybe4. Not telling us what you do get with it5. Not giving us enough information   ;  OK sorry for inconvenience.My question is how to create index buffer to receive square element. I set index buffer in the function that I insert in the first posting.regardsKamen   ;Quote:Original post by f1engineerMy question is how to create index buffer to receive square element. I set index buffer in the function that I insert in the first posting.You seem to already be doing it.  You're shoving the vertices into the vertex buffer and the indices into the index buffer.  What's the problem?   ;  Thank You for the answer.The problem is I want do draw a square on the screen, but a triangle appear instead . My be I miss something when creating the mesh or setting index buffer.best regardsKamen   ;  did u intialize the Attribute bufferif u didn't it can be the problemtry adding this to your codeDWORD *data;m_pMesh->LockAttributeBuffer(0,&data);for(int i=0;i<nNumFaces;i++){data = 0;}m_pMesh->UnlockAttributeBuffer();;  OKThank You friend. I shall try it.Best regards   ;  Your indexing is messed up, I think.// this is CWpIB[0] = 0;pIB[1] = 1;pIB[2] = 2;// this is CCWpIB[3] = 0;pIB[4] = 3;pIB[5] = 2;That means you will only see it if you turn off backface culling and render it using triangle list.Try 2,3,1,1,3,0 for 2 CW triangles with T-list or 2,3,1,0 for T-strip.   ;  Trying to draw a square and getting a triangle usually means you've got inconsistent winding orders for the two triangles in the square.  You can validate this by turning off culling.  If both triangles are drawn when face culling is disabled, then your problem is your winding order.  Fix the winding order; turning off culling is not the solution because your back facing triangles that were previously culled will now be lit incorrectly.   ;  Thank You a lot ofHow can I turn off culling? Also when create mesh where I can set to use triangle strip or triangle list?If possible show me it in the function in my first post.Best regards[Edited by - f1engineer on August 28, 2007 6:12:16 AM]