I am hacking a game called mount and blade and I want to draw an ESP overlay with directx drawindexedprimitive. However when I try to draw my shape it sometimes glitches out to the top left of the corner. I was hoping somebody could check my code and see what I am doing wrong. Here is an example
my d3dx9 test bench showing my drawing functions work just fine.

my triangle being drawn fine

one of my vertices randomly going to the top corner

my code
void CDraw::DrawTrapeziumFilled(int x, int y, int h, int w, int s, DWORD color)
{
CUSTOMVERTEX vertices[] =
{
{ x - w, y , 1.0f, 1.0f, color }, // vertex 0
{ x, y - h, 1.0f, 1.0f, color }, // vertex 1
{ x + w, y, 1.0f, 1.0f, color }, // vertex 2
};
unsigned short indexes[] = {
0,1,2
};
pDevice->CreateVertexBuffer(3 * sizeof(vertex), D3DUSAGE_WRITEONLY, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, D3DPOOL_DEFAULT, &buffer, NULL);
pDevice->CreateIndexBuffer(1 * sizeof(short), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &indexBuffer, NULL);
VOID* pVoid;
buffer->Lock(0, sizeof(vertices), (void**)&pVoid, 0);
memcpy(pVoid, vertices, sizeof(vertices));
buffer->Unlock();
VOID* pIndex;
indexBuffer->Lock(0, sizeof(indexes), (void**)&pIndex, 0);
memcpy(pIndex, indexes, sizeof(indexes));
indexBuffer->Unlock();
pDevice->SetIndices(indexBuffer);
pDevice->SetTexture(0, NULL);
pDevice->SetPixelShader(NULL);
pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
pDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
pDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
pDevice->SetStreamSource(0, buffer, 0, sizeof(vertex));
pDevice->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE);
pDevice->DrawIndexedPrimitive(D3DPT_TRIANGLESTRIP, 0, 0, 3, 0, 2);
buffer->Release();
indexBuffer->Release();
}
These drawings take place in present because in endscene the shaps would cause my entire screen to flicker. weird...
I am but a mere novice in directx and more used to openGL so I would be happy if somebody could point out to me what I am doing wrong
