LPDIRECT3DDEVICE::DrawPrimitiveUP只绘制黑白

LPDIRECT3DDEVICE::DrawPrimitiveUP only drawing in black and white

本文关键字:黑白 绘制 DrawPrimitiveUP LPDIRECT3DDEVICE      更新时间:2023-10-16
struct tri_vertex 
{ 
    float x, y, z, h;
    D3DCOLOR color;
};
void Draw2DLine(float x1, float y1, float x2, float y2, D3DCOLOR dwColor)
{
    tri_vertex vertices[2] = 
    {
        x1, y1, 0.0f, 1.0f, dwColor,
        x2, y2, 0.0f, 1.0f, dwColor,
    };
    pDevice->DrawPrimitiveUP(D3DPT_LINELIST, 1, vertices, sizeof(tri_vertex));
} 

pDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_TRUE );
pDevice->SetRenderState( D3DRS_LIGHTING, false ); 
pDevice->SetTexture( NULL, NULL );
pDevice->SetPixelShader( NULL );
// If commented out, the block drawn is black. Otherwise its completely white.
pDevice->SetVertexShader( NULL );
// For transparency 
pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
pDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
pDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);
pDevice->SetRenderState(D3DRS_BLENDOP,D3DBLENDOP_ADD);
pDevice->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);

我试图用DrawPrimitiveUP()画一条简单的线。然而,绘制的线是完全黑色或白色,这取决于SetVertexShader是否为空。它也不支持透明

然而,绘制的线要么完全是黑色的,要么完全是白色的SetVertexShader为null

你想要什么?彩色的线吗?线条的颜色设置好了吗?

它也不支持透明

您将纹理设置为null,因此混合对线条没有影响。