Original Post
I'm trying to dynamically allocate some polys, but I haven't been able to figure out how just yet. This code is in my render loop, so far. Here is my code: The problem lies in sending the objArg pointer to the objData array. Wow, I'm sure i'm going to get flamed for this, but salvo away!! [Edited by - argonaut on March 31, 2007 10:54:31 PM]
static int startCount = GetTickCount();
static float cx = 0;
// calculate the size of the new vertex
int objCount = 1 + (GetTickCount() - startCount) / 1000;
// create a new vertex data set
stD3DVertex *objData = new stD3DVertex[objCount];
// loop through to create the new vertex data set
for(int i = 0; i < objCount; i++)
{
cx = i + 0.5f - (float)(rand() % 1000) / 1000.0f;
// objectargs must be delivered independently
stD3DVertex objArg[] = { {-2.5f - cx, -0.5f, -6.0f, D3DCOLOR_ARGB(255,255,255,255), 0.0f, 1.0f},
{2.5f, -0.5f, -6.0f, D3DCOLOR_ARGB(255,255,255,255), 1.0f, 1.0f},
{2.5f, -0.5f, 6.0f, D3DCOLOR_ARGB(255,255,255,255), 1.0f, 0.0f},
{2.5f, -0.5f, 6.0f, D3DCOLOR_ARGB(100,255,255,255), 1.0f, 0.0f},
{-2.5f - cx, -0.5f, 6.0f, D3DCOLOR_ARGB(100,255,255,255), 0.0f, 0.0f},
{-2.5f - cx, -0.5f, -6.0f, D3DCOLOR_ARGB(100,255,255,255), 0.0f, 1.0f}
};
// deliver the data set to the vertex buffer
objData = *objArg;
}
// Create the vertex buffer.
if(FAILED(g_D3DDevice->CreateVertexBuffer(sizeof(objData), 0,
D3DFVF_VERTEX, D3DPOOL_DEFAULT,
&g_VertexBuffer, NULL))) return;
// Fill the vertex buffer.
void *ptr;
if(FAILED(g_VertexBuffer->Lock(0, sizeof(objData),
(void**)&ptr, 0))) return ;
memcpy(ptr, objData, sizeof(objData));
g_VertexBuffer->Unlock();