LPDIRECT3DDEVICE :: DrawPrimitiveUP仅绘制黑色和白色

时间:2014-06-04 02:51:38

标签: c++ line direct3d primitive direct3d9

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是否为空。它也不支持透明度。

1 个答案:

答案 0 :(得分:0)

  

然而,绘制的线条完全是黑色或白色   在SetVertexShader被取消

你有什么期望?彩色线?你设置了线条颜色吗?

  

它也不支持透明度。

您将纹理设置为null,因此混合对该行没有任何影响。