Original Post
When I make a call to this function my app crashes. What am I doing wrong?
LPDIRECT3DVERTEXBUFFER8 g_square;
struct my_vertex{
FLOAT x, y, z, rhw; // The transformed position for the vertex.
DWORD color; // The vertex color.
};
my_vertex g_square_vertices[] ={
{ 250.0f, 200.0f, 0.5f, 1.0f, 0x00000000 },
{ 250.0f, 50.0f, 0.5f, 1.0f, 0x00000000 },
{ 400.0f, 200.0f, 0.5f, 1.0f, 0x00000000 },
{ 400.0f, 50.0f, 0.5f, 1.0f, 0x00000000 }
};
Here is the function
DrawBox(float Xpos, float Ypos, float width, float height, DWORD Color)
{
unsigned char *Temp_Vertexbuff;
//top left of box
g_square_vertices[0].color = Color;
g_square_vertices[0].x = Xpos;
g_square_vertices[0].y = Ypos;
g_square_vertices[0].z = 20.0f;
g_square_vertices[0].rhw = 1.0f;
//bottom left of box
g_square_vertices[1].color = Color;
g_square_vertices[1].x = Xpos;
g_square_vertices[1].y = Ypos + height;
g_square_vertices[1].z = 20.0f;
g_square_vertices[1].rhw = 1.0f;
//top right of box
g_square_vertices[2].color = Color;
g_square_vertices[2].x = Xpos + width;
g_square_vertices[2].y = Ypos;
g_square_vertices[2].z = 20.0f;
g_square_vertices[2].rhw = 1.0f;
//bottom right of box
g_square_vertices[3].color = Color;
g_square_vertices[3].x = Xpos + width;
g_square_vertices[3].y = Ypos + height;
g_square_vertices[3].z = 20.0f;
g_square_vertices[3].rhw = 1.0f;
g_square->Lock(0, 0, &Temp_Vertexbuff, 0);
memcpy(Temp_Vertexbuff, g_square_vertices, sizeof(g_square_vertices));
g_square->Unlock();
pDirect3DDevice->BeingScene();
pDirect3DDevice->SetVertexShader(D3D8T_CUSTOMVERTEX);
pDirect3DDevice->SetStreamSource(0, g_square, sizeof(my_vertex));
pDirect3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
pDirect3DDevice->EndScene();
}