1
我嘗試使用Direct2D繪製矩形。初始化的Direct2D設備和Direct2D的設備上下文和設置渲染目標,在下面的描述MSDN article後,我試圖繪製一個矩形,如下所示:ID2D1DeviceContext EndDraw繪製矩形後的D2DERR_WRONG_STATE
HRESULT result;
result = g_d2dContext->CreateSolidColorBrush(
D2D1::ColorF(D2D1::ColorF::Blue),
&g_SolidBrush
);
D2D1_RECT_F rect = D2D1::RectF(
g_targetRect.left + 10.0f,
g_targetRect.top + 10.0f,
g_targetRect.right - 10.0f,
g_targetRect.bottom - 10.0f);
g_d2dContext->BeginDraw();
{
g_d2dContext->DrawRectangle(rect, g_SolidBrush, 5.0f);
}
result = g_d2dContext->EndDraw();
if (FAILED(result))
{
OutputDebugStringW(L"The object was not in the correct state to process the method.");
}
的EndDraw()方法返回下列HRESULT:0x88990001 (D2DERR_WRONG_STATE) - The object was not in the correct state to process the method
。
矩形不會被繪製。我只得到一個黑色的圖像。
編輯:
我假設的問題是,得到一個NULL指針位圖/調用CreateBitmapFromDxgiSurface後渲染目標。
g_d2dContext->CreateBitmapFromDxgiSurface(
dxgiBackBuffer.Get(),
&bitmapProperties,
&g_targetBitmap);
g_d2dContext->SetTarget(g_targetBitmap.Get());
但是爲什麼targetBitmap是NULL?
任何想法?
在此先感謝。