Jump to content


create mesh by D3DXCreateMeshFVF


  • You cannot reply to this topic
3 replies to this topic

#1 f1engineer

    New Member

  • Members
  • PipPip
  • 18 posts

Posted 06 February 2008 - 10:04 AM

Dear Sirs

I try to make mesh by creating vertex buffer and index buffer as next code:


void CD3DSimulationView::CreateMeshes()
{
	unsigned short nNumFaces = 12;
	unsigned short nNumVertices = 8;
	
	D3DXCreateMeshFVF(nNumFaces, nNumVertices, D3DXMESH_VB_MANAGED, D3DFVF_XYZ, m_pd3dDevice, &m_pMesh);

	//m_pMesh - is object declared in CD3DSimulationView
	
	CUSTOMVERTEX* pVertices;
	m_pMesh->LockVertexBuffer(D3DLOCK_DISCARD, (void**)&pVertices);
	
	float front   = -1.0;
	float back    =  1.0;
	
	float left    = -1.0;
	float right   =  1.0;
	
	float top     =  1.0;
	float bottom  = -1.0;
	
	pVertices[0].m_pVertices = D3DXVECTOR3(left, bottom, front);
	pVertices[1].m_pVertices = D3DXVECTOR3(right, bottom, front);
	
	pVertices[2].m_pVertices = D3DXVECTOR3(left, top, front);
	pVertices[3].m_pVertices = D3DXVECTOR3(right, top, front);
	
	pVertices[4].m_pVertices = D3DXVECTOR3(left, bottom, back);
	pVertices[5].m_pVertices = D3DXVECTOR3(right, bottom, back);
	
	pVertices[6].m_pVertices = D3DXVECTOR3(left, top, back);
	pVertices[7].m_pVertices = D3DXVECTOR3(right, top, back);
	
	m_pMesh->UnlockVertexBuffer();
	
	UINT *pIB = NULL;
	m_pMesh->LockIndexBuffer( 0, (void**)&pIB);
	
	short leftbottomfront   = 0; 
	short rightbottomfront  = 1; 
	short lefttopfront      = 2; 
	short righttopfront     = 3;
	short leftbottomback    = 4;
	short rightbottomback   = 5; 
	short lefttopback       = 6;
	short righttopback      = 7; 
	
	pIB[0] = lefttopfront;
	pIB[1] = lefttopback;
	pIB[2] = leftbottomback;
	
	pIB[3] = leftbottomback;
	pIB[4] = leftbottomfront;
	pIB[5] = lefttopfront;
	
	pIB[6] = lefttopfront;
	pIB[7] = leftbottomfront;
	pIB[8] = rightbottomfront;
	
	pIB[9] = rightbottomfront;
	pIB[10] = righttopfront;
	pIB[11] = lefttopfront;
	
	pIB[12] = righttopback;
	pIB[13] = righttopfront;
	pIB[14] = rightbottomfront;
	
	pIB[15] = rightbottomfront;
	pIB[16] = rightbottomback;
	pIB[17] = righttopback;
	
	pIB[18] = leftbottomback;
	pIB[19] = lefttopback;
	pIB[20] = righttopback;
	
	pIB[21] = righttopback;
	pIB[22] = rightbottomback;
	pIB[23] = leftbottomback;
	
	pIB[24] = righttopfront;
	pIB[25] = righttopback;
	pIB[26] = lefttopback;
	
	pIB[27] = lefttopback;
	pIB[28] = lefttopfront;
	pIB[29] = righttopfront;
	
	pIB[30] = leftbottomfront;
	pIB[31] = leftbottomback;
	pIB[32] = rightbottomback;
	
	pIB[33] = rightbottomback;
	pIB[34] = rightbottomfront;
	pIB[35] = leftbottomfront;
	
	m_pMesh->UnlockIndexBuffer();
	
	Render();
}


But when I run render process of the created mesh, no object on the screan appear as I expect.
I need to create parallelipiped. What is that I miss in my function.

Is it possible to send me some examples or links that I shall be able to find more information.

Sincerely Yours
Kamen

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 4979 posts
  • LocationBellevue, WA

Posted 06 February 2008 - 07:29 PM

For future reference, the tags are [code]...[/code], not <source>...</source>.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 starstutter

    Senior Member

  • Members
  • PipPipPipPip
  • 1039 posts

Posted 07 February 2008 - 12:12 AM

I'm not %100 sure this is your problem, but I notice your not setting the attribute buttfer with anything:


             DWORD *att = 0;

	m_pMesh->LockAttributeBuffer(0,&att);

	memset(att, 0, sizeof(DWORD)*nNumFaces);

	m_pMesh->UnlockAttributeBuffer();


this will make it so that when you say "mesh->DrawSubset(0);", that '0' will actually have meaning. If you don't know what the attribute buffer does, it's kind of like it sounds. It attributes verticies and triangles to different drawing levels.

Like for instance, on a person mesh, putting all your body verticeis in "attribute 0", and then putting the head vertices in "attribute 1", will make it so:

DrawSubset(0); //draws only the body and not the head

DrawSubset(1); //draws only the head and not the body

If you don't define all these, it assumes that there are 0 verticies to draw in "attribute 0".


Other than this I can only recommend:
- Double check to see if your index buffer is correct
- Make sure that you have alpha off and that your mesh is just not visible (I'm guilty of it)
- Make sure that your mesh isn't just drawing in a place you can't see, sounds like a dumb mistake, but again, done it too many times

#4 f1engineer

    New Member

  • Members
  • PipPip
  • 18 posts

Posted 07 February 2008 - 07:33 AM

Thank You Sir for comprehensive answer.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users