Original Post
How can I make a solid filled rectangle in Direct3D? I made the code below but is generates a transparant rectangle (I do use alpha channel at full, 0xFF however). During my game I use the D3DXSprite interface and D3DXLine interface (I can make a rectangle from a series of lines though, but I don't think it's the fastest way). I should do it with an untextured quad I think, but how? I read that DrawPrimitiveUP is relatively slow so I should use a texture buffeR?
HRESULT DrawRectangle(const RECT* lpRectangle, D3DCOLOR Color)
{
CUSTOM_VERTEX Vertices[4] =
{
(float) lpRectangle->left - 0.5f, (float) lpRectangle->top - 0.5f, 0.5f, 1.0f, Color, 0, 0,
(float) lpRectangle->right - 0.5f, (float) lpRectangle->top - 0.5f, 0.5f, 1.0f, Color, 0, 0,
(float) lpRectangle->right - 0.5f, (float) lpRectangle->bottom - 0.5f, 0.5f, 1.0f, Color, 0, 0,
(float) lpRectangle->left - 0.5f, (float) lpRectangle->bottom - 0.5f, 0.5f, 1.0f, Color, 0, 0,
};
LPDIRECT3DDEVICE9 lpD3DDevice = m_Video->GetD3DDevice();
m_Video->GetD3DSprite()->Flush();
IDirect3DVertexDeclaration9* lpD3DVertexDeclaration = NULL;
lpD3DDevice->GetVertexDeclaration(&lpD3DVertexDeclaration);
lpD3DDevice->SetFVF(D3DFVF_CUSTOM_VERTEX);
lpD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_DISABLE );
lpD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
lpD3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, Vertices, sizeof(CUSTOM_VERTEX));
lpD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
lpD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
lpD3DDevice->SetVertexDeclaration(lpD3DVertexDeclaration);
lpD3DVertexDeclaration->Release();
return S_OK;
}