Jump to content


.X mesh indexbuffer help


7 replies to this topic

#1 Anddos

    Valued Member

  • Members
  • PipPipPip
  • 161 posts

Posted 15 March 2008 - 11:29 AM

i am trying to get each X,Y,Z of the index buffer , i want the same as when you get the GetvertexBuffer but that has random points so that its alot harder to draw a triangle strip on the mesh and see it in wireframe render state
after locking i cant think how you go through the data that was locked to get each X,Y,Z floats

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 4979 posts
  • LocationBellevue, WA

Posted 15 March 2008 - 04:42 PM

The index buffer doesn't have XYZs, it just has indices into the vertex buffer. You need the XYZ locations stored in the vertex buffer, but accessed in the order dictated by the index buffer.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 Anddos

    Valued Member

  • Members
  • PipPipPip
  • 161 posts

Posted 15 March 2008 - 06:07 PM

can you show me a sample?

#4 Reedbeta

    DevMaster Staff

  • Administrators
  • 4979 posts
  • LocationBellevue, WA

Posted 15 March 2008 - 06:48 PM

It's really, really, simple. The index buffer is a list of integers. If the index buffer says 0, 2, 3, 1, ... that means the vertices are vbuffer[0], vbuffer[2], vbuffer[3], vbuffer[1], and so on...
reedbeta.com - developer blog, OpenGL demos, and other projects

#5 Anddos

    Valued Member

  • Members
  • PipPipPip
  • 161 posts

Posted 15 March 2008 - 06:57 PM

It's really, really, simple. The index buffer is a list of integers. If the index buffer says 0, 2, 3, 1, ... that means the vertices are vbuffer[0], vbuffer[2], vbuffer[3], vbuffer[1], and so on...

and those indexs are stored as lpIB[0] , lpIB[1] , lpIB[2].......?
i cant seem to output it to a messagebox

sprintf(data , "%s %i" ,"lpIB[0]" , lpIB[0]);
MessageBox(NULL,data,"",0);
error C2109: subscript requires array or pointer type

#6 Reedbeta

    DevMaster Staff

  • Administrators
  • 4979 posts
  • LocationBellevue, WA

Posted 15 March 2008 - 07:08 PM

Yes that's how ANY array works.
reedbeta.com - developer blog, OpenGL demos, and other projects

#7 Anddos

    Valued Member

  • Members
  • PipPipPip
  • 161 posts

Posted 15 March 2008 - 07:36 PM


HRESULT D3DXMeshClass::ExtractVerticesFromIndexBuffer(LPD3DXMESH Spaceship)

{

	BYTE* lpbVb;

	BYTE *lpIB;


	//get the vertex buffer

	cHresult = Spaceship->LockVertexBuffer( D3DLOCK_READONLY, (VOID**)&lpbVb );

	

	if(cHresult == D3D_OK)

	{

		MessageBox(NULL,"Lock VerteBuffer Success","",0);

	}

	cHresult = Spaceship->LockIndexBuffer ( D3DLOCK_READONLY, (VOID**)&lpIB); 

	

	if(cHresult == D3D_OK)

	{

		MessageBox(NULL,"Lock IndexBuffer Success","",0);

	}


	cHresult = Spaceship->GetIndexBuffer( &lpIndexBuffer );

	

	if(cHresult == D3D_OK)

	{

		MessageBox(NULL,"Get IndexBuffer Success","",0);

	}


	cHresult = lpIndexBuffer->GetDesc( &ibdesc );

	

	if(cHresult == D3D_OK)

	{

		MessageBox(NULL,"GetDesc Success","",0);

	}


	if(ibdesc.Format == D3DFMT_INDEX32)

	{

		MessageBox(NULL,"ibdesc.Format 32","",0);

		numIndices = ibdesc.Size / sizeof(DWORD);

	}

	else

	{

		MessageBox(NULL,"ibdesc.Format 16","",0);

		numIndices = ibdesc.Size / sizeof(WORD);


	}


	numBytesPerVertex = Spaceship->GetNumBytesPerVertex();


	for(int i=0; i<numIndices; i += 3 )

	{

		//sprintf(data, "%s %d" , "loop count" , i);

		//MessageBox(NULL,data,"",0);

		if (ibdesc.Format == D3DFMT_INDEX32  )

	    {

				idxVbVert0 = ((DWORD*)lpIB)[ i ];

				idxVbVert1 = ((DWORD*)lpIB)[ i+1 ];

				idxVbVert2 = ((DWORD*)lpIB)[ i+2 ];

	    }

		else

		{

				idxVbVert0 = ((WORD*)lpIB)[ i ];

				idxVbVert1 = ((WORD*)lpIB)[ i+1 ];

				idxVbVert2 = ((WORD*)lpIB)[ i+2 ];

		}

		

		D3DXVECTOR3 v0 = *(D3DXVECTOR3*) &lpbVb[ idxVbVert0 * numBytesPerVertex ];

	    D3DXVECTOR3 v1 = *(D3DXVECTOR3*) &lpbVb[ idxVbVert1 * numBytesPerVertex ];

		D3DXVECTOR3 v2 = *(D3DXVECTOR3*) &lpbVb[ idxVbVert2 * numBytesPerVertex ];


		sprintf(data, "%s %f" , "v0.x" ,  v0.x);

		MessageBox(NULL,data,"",0);

	}


//Unlock()

	Spaceship->UnlockVertexBuffer();

	Spaceship->UnlockIndexBuffer();


	return D3D_OK;

}



#8 Anddos

    Valued Member

  • Members
  • PipPipPip
  • 161 posts

Posted 16 March 2008 - 08:43 AM

is this doing the right think now ?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users