0

In order to draw and erase lines on the background image of the artboard, I created an RTT texture, painted various lines on it, and then rendered the texture, but now I see the edges with the ambient color(the black dots) when I cross the lines. I hope to get rid of this "noise".

As indicated by the yellow arrow, the black dots at the intersection of the lines

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);
Kami Kaze
  • 2,069
  • 15
  • 27
fredirty2017
  • 103
  • 11
  • Looks like antialiasing, without transparency on edge – Stranger in the Q Sep 28 '18 at 06:47
  • thanks advice, I only know a little bit about anti-aliasing. but The problem is still exist event createdevice i set D3DPRESENT_PARAMETERS; d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE; d3dpp.MultiSampleQuality = 0; and _pID3dDev->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, FALSE); – fredirty2017 Sep 28 '18 at 06:58
  • Turn it off and show result plz – Stranger in the Q Sep 28 '18 at 06:59
  • Or try to use transparent color instead of black – Stranger in the Q Sep 28 '18 at 07:01
  • use white or other color(IDirect3DDevice9::Clear color param) can't remove the noise,or i don't konw how to set "transparent color"。 – fredirty2017 Sep 28 '18 at 07:18
  • Your source & destination alpha blend settings look odd. I'd start with those per [MSDN](https://learn.microsoft.com/en-us/windows/desktop/direct3d9/alpha-blending-state). Of course I'd also recommend not using legacy Direct3D 9 and the deprecated D3DX9 utility library (see [MSDN](https://learn.microsoft.com/en-us/windows/desktop/directx-sdk--august-2009-)). Direct3D 11 with Direct2D is a better choice for fancy line drawing. – Chuck Walbourn Sep 29 '18 at 06:41

0 Answers0