I'm attempting to use a Direct2D feature called an opacity mask where the alpha values from one PNG image are used to determine the transparency of another image: http://msdn.microsoft.com/en-us/library/windows/desktop/ee329947%28v=vs.85%29.aspx
First, I create a
ID2D1BitmapBrush* using an
ID2D1Bitmap* (the actual image to be rendered):
pRenderTarget->CreateBitmapBrush( pMyBitmap, ppBitmapBrush);
Then I set the render target's antialiasing mode and call
FillOpacityMask() using the mask bitmap (also a
ID2D1Bitmap*) and BitmapBrush I just created:
pRenderTarget->SetAntialiasMode(D2D1_ANTIALIAS_MODE_ALIASED); D2D1_RECT_F rect = D2D1::RectF(100.0f, 100.0f, 214.0f, 214.0f); pRenderTarget->FillOpacityMask(pMaskBitmap, *ppBitmapBrush, D2D1_OPACITY_MASK_CONTENT_GRAPHICS, &rect, &rect);
S_OK so I know that the operation succeeded but the results are not as expected. I have edited the alpha channel of the mask image so that certain areas of the image should be more transparent than others.
However, the result is that the entire rectangle is drawn. No areas of the rectangle are transparent, it is completely opaque.
I have tried adjusting the alpha mode and pixel format on the render target:
D2D1_RENDER_TARGET_PROPERTIES p = D2D1::RenderTargetProperties(); p.pixelFormat.format = DXGI_FORMAT_B8G8R8A8_UNORM; p.pixelFormat.alphaMode = D2D1_ALPHA_MODE_PREMULTIPLIED;
and then using that as an argument in
CreateHwndRenderTarget() but it doesn't seem to help.
Am I missing something?