Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

ISOPimp

VertexBuffer with Dynamic Vertexes

This topic is 5527 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How do I fill a vertex buffer with a dynamic number of vertexes? Here is a nice non-working example:
int Triangles = 2; //dynamic number

int TrianglePoints = Triangles * 3;
VERTEX *sVertices = new VERTEX[TrianglePoints];

//vertex information

for(int i=0; i < TrianglePoints; ++i)
{
	if((i+1)%3 == 0)
	{
		long x = (rand()%10) - 5;
		long y = (rand()%10) - 5;
		long z = (rand()%10) - 5;
		sVertices[i-2].vPosition = D3DXVECTOR3(-1 + x,-1 + y, z);
		sVertices[i-1].vPosition = D3DXVECTOR3(-1 + x, 1 + y, z);
		sVertices[i-0].vPosition = D3DXVECTOR3( 0 + x, 0 + y, z);
	}
}

VOID* pVertices;
g_pD3DDevice->CreateVertexBuffer( TrianglePoints * sizeof(VERTEX), 0, FVF_VERTEX, D3DPOOL_MANAGED, g_pD3DVB_VERTEX, 0);
g_pD3DVB_VERTEX->Lock(0, sizeof(sVertices), &pVertices, 0);
memcpy(pVertices, sVertices, sizeof(sVertices));
g_pD3DVB_VERTEX->Unlock();

SafeDeleteArray(sVertices);
Anyone?

Share this post


Link to post
Share on other sites
Advertisement
g_pD3DVB_VERTEX->Lock(0, sizeof(sVertices), &pVertices, 0);
memcpy(pVertices, sVertices, sizeof(sVertices));

sVertices is a dynamic array/pointer. I believe the use of the sizeof operator will give you 4 (the actuall size of the pointer). This is contrary to the sizeof operator use on a satic array in which case it gives the actaull size of the array.

So what you should try is.

g_pD3DVB_VERTEX->Lock(0, TrianglePoints * sizeof(VERTEX), &pVertices, 0);
memcpy(pVertices, sVertices, TrianglePoints * sizeof(VERTEX));

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!