My vertex buffer:
IDirect3DVertexBuffer8 *VBMain = NULL;
My structure looks like this:
Code:
struct MyVertex
{
FLOAT X, Y, Z; //Coordinates on screen
FLOAT TU, TV; //Texture Coordinates
};
Then, to make my program more efficient, until now I have been declaring my vertices like this:
Code:
MyVertex AllVertices[];=
{
//TRIANGLE
{-0.5f, 0.5f, 0.0f, 0.75f, 0.750f},
{ 0.5f, 0.0f, 0.0f, 1.00f, 0.875f},
{-0.5f, -0.5f, 0.0f, 0.75f, 1.000f},
//SQUARE 1
{-0.0f, 0.0f, 0.0f, 0.0f, 0.0f},
{ 0.0f, 0.0f, 0.0f, 0.5f, 0.0f},
{-0.0f, -0.0f, 0.0f, 0.0f, 0.5f},
{ 0.0f, -0.0f, 0.0f, 0.5f, 0.5f},
//SQUARE 2
{-25.0f, -19.00f, 0.0f, 0.0f, 0.50f},
{-20.0f, -19.0f, 0.0f, 1.0f, 0.50f},
{-25.0f, -20.00f, 0.0f, 0.0f, 0.75f},
{-20.0f, -20.00f, 0.0f, 1.0f, 0.75f},
};
Keeping all of my vertices for my entire program in one array.
Then, I passed my AllVertices variable into VBMain with:
Code:
HRESULT Attempt;
unsigned char *VBVertices;
Attempt = VBMain->Lock(0, 0, &VBVertices, 0);
if (FAILED(Attempt))
{
MessageBox(NULL, "Could Not Lock Vertex Buffer", "Error", MB_OK|MB_TOPMOST);
return false;
}
memcpy(VBVertices, AllVertices, sizeof(AllVertices));
VBMain->Unlock();
So, in essence, I've been hardcoding my vertices into my code and have been working with that.
Now, what I want to do is get rid of the hardcoding and create functions to add vertices to my AllVertices[] variable. Meaning, I was hoping to declare AllVertices with:
Code:
MyVertex AllVertices[];
Allowing me to add as much data to the array as needed. But, I come across problems.
One problem comes from this line:
Code:
D3DDevice->CreateVertexBuffer(NUM_VERTICES * sizeof(MyVertex), D3DUSAGE_WRITEONLY, D3D8T_CUSTOMVERTEX, D3DPOOL_MANAGED, &VBMain);
Where NUM_VERTICES is:
Code:
#define NUM_VERTICES (sizeof(AllVertices)/sizeof(MyVertex))
From this, NUM_VERTICES will equal 0. Meaning I'm creating a VertexBuffer with "Length" 0. C++ doesn't like that.
I'm asking, whether there is a better way around this than declaring:
MyVertex AllVertices[5000];
at the beginning because the functions I am creating to append to the array may be called often enough that eventually, that 5000 (or whichever number I choose) might be exceeded.
(Hope that clears up my question a bit And thanks for sticking with it so far )