I'm learning C++ and graphics programming, and following a tutorial, but I can't seem to be able to find any solutions to this problem.
This is the code:
struct CUSTOMVERTEX { FLOAT X, Y, Z; DWORD COLOR; };
void writetovram(struct CUSTOMVERTEX *verticies)
{
...
memcpy(pVoid, verticies, sizeof(verticies));
...
return;
}
void createshapes()
{
//simple square
CUSTOMVERTEX verticies[] =
{
{ -3.0f, 3.0f, 0.0f, D3DCOLOR_XRGB(0, 0, 255), },
{ 3.0f, 3.0f, 0.0f, D3DCOLOR_XRGB(0, 255, 0), },
{ -3.0f, -3.0f, 0.0f, D3DCOLOR_XRGB(255, 0, 0), },
{ 3.0f, -3.0f, 0.0f, D3DCOLOR_XRGB(0, 255, 255), },
};
writetovram(&verticies);
}
I need to be able to pass this struct array in its entirety as a pointer to the function. I've found that if I havn't used pointers then the data doesn't get transferred properly.
I've tried:
void writetovram(struct CUSTOMVERTEX *verticies)
void writetovram(struct CUSTOMVERTEX verticies)
void writetovram(struct CUSTOMVERTEX &verticies)
void writetovram(struct CUSTOMVERTEX *verticies[])
void writetovram(struct CUSTOMVERTEX verticies[])
and
writetovram(&verticies);
writetovram(*verticies);
writetovram(verticies);
Edit: When I put the code like this, it works:
void writetovram()
{
CUSTOMVERTEX verticies[] =
{
{ -3.0f, 3.0f, 0.0f, D3DCOLOR_XRGB(0, 0, 255), },
{ 3.0f, 3.0f, 0.0f, D3DCOLOR_XRGB(0, 255, 0), },
{ -3.0f, -3.0f, 0.0f, D3DCOLOR_XRGB(255, 0, 0), },
{ 3.0f, -3.0f, 0.0f, D3DCOLOR_XRGB(0, 255, 255), },
};
...
memcpy(pVoid, verticies, sizeof(verticies));
...
return;
}
Basically, all the combinations of pointers and syntax I could think of. But none have worked.
Can anyone help?
I've also searched online and found none having this problem.