我如何清除的Direct2D渲染目标,以完全透明 [英] How do I clear a Direct2D render target to fully transparent
问题描述
我试图借鉴一种无形的HWND半透明矩形。但是,清除与ID2D1HwndRenderTarget ::清除窗口只是使整个窗口黑色的,所以当我画在上面的矩形,它们看起来半黑的。
I'm trying to draw semi-transparent rectangles on an invisible HWND. However, clearing the window with ID2D1HwndRenderTarget::Clear just makes the entire window black, so when I draw rectangles on top, they look semi-black.
如果我不清除()和不画,则该窗口是看不见的,因为它应该是。清除()是这里的罪魁祸首;但是如果我不使用它,然后画严重打乱了pretty。
If I don't Clear() and don't draw, then the window is invisible, as it should be. Clear() is the culprit here; however if I don't use it then painting messes up pretty badly.
这里的code,我用我的WindowProc:
Here's the code I'm using in my WindowProc:
case WM_PAINT:
// Begin drawing
pRenderTarget->BeginDraw();
pRenderTarget->SetTransform(D2D1::Matrix3x2F::Identity());
// Clear the window
pRenderTarget->Clear();
// Paint the panel and its children
D2DSurface()->StartPainting();
{
D2DSurface()->PaintTraverse(panel);
}
D2DSurface()->FinishPainting();
// Finish drawing
HRESULT hr = plat->pRenderTarget->EndDraw();
在此先感谢!
推荐答案
在创建的RenderTarget,你必须告诉您要使用阿尔法(以premultiplied模式)的像素格式D2D:
When creating your RenderTarget, you'll have to tell D2D that you want to use alpha (in premultiplied mode) in the pixel format:
HRESULT hr = mD2DFactory->CreateHwndRenderTarget(
D2D1::RenderTargetProperties( D2D1_RENDER_TARGET_TYPE_DEFAULT, D2D1::PixelFormat( DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_PREMULTIPLIED ) ),
D2D1::HwndRenderTargetProperties( mWindow, size ),
&mRenderTarget );
在此之后,调用清除()
为零的Alpha值的作品就好。
After this, calling Clear()
with an alpha value of zero works just fine.
这篇关于我如何清除的Direct2D渲染目标,以完全透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!