2,791 questions
You can add a Shadow effect on anything you draw .
For example on a blue Rectangle :
pDeviceContext->BeginDraw();
pDeviceContext->Clear(D2D1::ColorF(D2D1::ColorF::White, 1.0f));
D2D1_SIZE_F renderTargetSize = pDeviceContext->GetSize();
ID2D1BitmapRenderTarget* pCompatibleRenderTarget = NULL;
HRESULT hr = pDeviceContext->CreateCompatibleRenderTarget(renderTargetSize, &pCompatibleRenderTarget);
if (SUCCEEDED(hr))
{
pCompatibleRenderTarget->BeginDraw();
//pCompatibleRenderTarget->Clear(D2D1::ColorF(D2D1::ColorF::White, 1.0f));
pCompatibleRenderTarget->Clear(NULL);
ID2D1SolidColorBrush* pBlackBrush = NULL;
pCompatibleRenderTarget->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Black), &pBlackBrush);
pCompatibleRenderTarget->FillRectangle(D2D1::RectF(50.f, 50.f, 250.f, 250.f), pBlackBrush);
SafeRelease(&pBlackBrush);
pCompatibleRenderTarget->EndDraw();
ID2D1Bitmap* pCompatibleBitmap = NULL;
hr = pCompatibleRenderTarget->GetBitmap(&pCompatibleBitmap);
if (SUCCEEDED(hr))
{
ID2D1Effect* pShadowEffect = NULL;
hr = pDeviceContext->CreateEffect(CLSID_D2D1Shadow, &pShadowEffect);
if (SUCCEEDED(hr))
{
pShadowEffect->SetValue(D2D1_SHADOW_PROP_BLUR_STANDARD_DEVIATION, 5.f);
pShadowEffect->SetInput(0, pCompatibleBitmap);
pDeviceContext->DrawImage(pShadowEffect,
D2D1::Point2F(10, 10),
D2D1::RectF(0, 0, renderTargetSize.width, renderTargetSize.height),
D2D1_INTERPOLATION_MODE_LINEAR,
D2D1_COMPOSITE_MODE_SOURCE_OVER
);
SafeRelease(&pShadowEffect);
}
SafeRelease(&pCompatibleBitmap);
}
SafeRelease(&pCompatibleRenderTarget);
ID2D1SolidColorBrush* pBlueBrush = NULL;
pDeviceContext->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Blue), &pBlueBrush);
pDeviceContext->FillRectangle(D2D1::RectF(50.f, 50.f, 250.f, 250.f), pBlueBrush);
SafeRelease(&pBlueBrush);
}
pDeviceContext->EndDraw();