如何在纹理中正确绘制线条

时间:2018-09-28 06:44:38

标签: textures d3dx

为了在画板的背景图像上绘制和擦除线条,我创建了一个RTT纹理,在其上绘制了各种线条,然后渲染该纹理,但是现在我看到具有环境颜色的边缘(黑点),当我越界时。我希望摆脱这种“噪音”。

here

if (_pILineTexture)
{
    D3DSURFACE_DESC desc;
    hr = _pILineTexture->GetLevelDesc(0, &desc);
    if (FAILED(hr))
    {
        return;
    }
    if (desc.Width != all_width || desc.Height != all_height)
    {
        _pILineTexture = nullptr;
    }
}
if (!_pILineTexture)
{
    hr = D3DXCreateTexture(_pID3dDev, all_width, all_height, 0, 
D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &_pILineTexture);
    if (FAILED(hr))
    {
        return;
    }
}
CComPtr<IDirect3DSurface9> pIOldSurface = nullptr;
_pID3dDev->GetRenderTarget(0, &pIOldSurface);    
CComPtr<IDirect3DSurface9> pIDstSurface = nullptr;
_pILineTexture->GetSurfaceLevel(0, &pIDstSurface);
_pID3dDev->SetRenderTarget(0, pIDstSurface);     
_pID3dDev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 
D3DCOLOR_RGBA(0, 0, 0, 0), 0.5f, 0);
_pID3dLine->Begin();
_pID3dDev->SetRenderState(D3DRS_LIGHTING, FALSE);//For XYZ
_pID3dDev->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
_pID3dDev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
_pID3dDev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ZERO);
_pID3dLine->DrawTransform(_points.data(), _points.size(), &matrix, 
D3DCOLOR_RGBA(255, 0, 0, 255));
_pID3dLine->End();
D3DXSaveTextureToFileA("G:\\Proj\\line.png", D3DXIFF_PNG, _pILineTexture, NULL);

0 个答案:

没有答案