IDirect3DVertexBuffer9* pBuffer = NULL;
int iSize = CubeOne.Size() + CubeTwo.Size();
pDevice->CreateVertexBuffer(iSize, 0, VertexFVF, D3DPOOL_DEFAULT, &pBuffer, NULL);
void* pVertices = NULL;
pBuffer->Lock(0, 0, (void**)&pVertices, 0);
memcpy(pVertices, CubeOne.GetVertices(), CubeOne.Size());
memcpy(&(pVertices + CubeOne.Size()), CubeTwo.GetVertices(), CubeTwo.Size());
pBuffer->Unlock();
Copying two sets of vertices into one vbuffer
I'm trying to get the vertices from my two cubes into one vertexbuffer and I can't figure out how to do it. This is what I have:
I'm pretty sure that the problem is with my second memcpy() call.
Any help would be appreciated!
Thanks
What's not working? Is it crashing? (If so, is it crashing on the second memcpy?) Is it not drawing the cubes correctly? (If so, what does draw?)
From your code, I don't immediately see anything wrong. I'm assuming all your size variables, functions, etc. are all in bytes.
From your code, I don't immediately see anything wrong. I'm assuming all your size variables, functions, etc. are all in bytes.
Hey,
I'm not 100% sure on this, but this code looks familiar to something I did with my network code when it came to constructing my final message. For the second memcpy call try something like this:
memcpy( pVertices[ CubeOne.size() ], CubeTwo.GetVertices(), CubeTwo.GetSize() );
This should tell memcpy to start at the index immediately following the last vertex (you may have to subtract one depending on how you handle your size) and copy CubeTwo.Size number of vertices.
Permafried-
I'm not 100% sure on this, but this code looks familiar to something I did with my network code when it came to constructing my final message. For the second memcpy call try something like this:
memcpy( pVertices[ CubeOne.size() ], CubeTwo.GetVertices(), CubeTwo.GetSize() );
This should tell memcpy to start at the index immediately following the last vertex (you may have to subtract one depending on how you handle your size) and copy CubeTwo.Size number of vertices.
Permafried-
the error I think is:
memcpy(&(pVertices + CubeOne.Size()), CubeTwo.GetVertices(), CubeTwo.Size());
you are taking the address of the address of the end point of cube1 data in the vbuffer. 2 levels of indirection. It oughta be crashing.
remove the & operator.
memcpy(&(pVertices + CubeOne.Size()), CubeTwo.GetVertices(), CubeTwo.Size());
you are taking the address of the address of the end point of cube1 data in the vbuffer. 2 levels of indirection. It oughta be crashing.
remove the & operator.
If I remove the & operator it tells me "void*" unknown size.
Okay, I've tracked it down to giving me an error on the pBuffer->Unlock() function.
Okay, I've tracked it down to giving me an error on the pBuffer->Unlock() function.
Quote:Original post by Programmer16
If I remove the & operator it tells me "void*" unknown size.
Pointer arithmetic - adding/subtracting/incrementing/decrementing pointers - requires knowing the size of the pointee type so that the address is incremented succesfully.
i.e. Basically, when you say:
int arr[5];int* pointer = arr;pointer += 3;
The pointer += 3 increments the address pointed to by the pointer by the value "3 * sizeof(int)" (i.e. multiplied by the size of the pointee type).
In short, either declare pVertices to be of your vertex type, or typecast it in the memcpy.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement