Combination of ID2D1PathGeometry and ID2D1DeviceContext

0

My goal is to draw a geometry path in a render target provided by a ID2D1DeviceContext. I have an ID2D1Factory created by D2D1CreateFactory and the following code fails:

CComPtr<ID2D1PathGeometry> m_pPathGeometry;
fa->CreatePathGeometry(&m_pPathGeometry);

CComQIPtr<ID2D1SolidColorBrush> b;
D2D1_COLOR_F cc = { 1.0f,1.0f,1.0f,1.0f };
pRT->CreateSolidColorBrush(cc, &b);
pRT->FillGeometry(m_pPathGeometry, b);

When calling pRT->EndDraw(), I get a message 0x88990012 : Objects used together must be created from the same factory instance.

Why ? Does that mean that the path geometry is only compatible with a render target created with fa->CreateHwndRenderTarget() ? But I need of course a ID2D1DeviceContext for rendering into a bitmap.

c++
winapi
direct2d

1 Answer

1

My crystal ball tells me that you are creating ID2D1DeviceContext instance by invoking D2D1CreateDeviceContext function which also creates a new factory object and then you create another factory by invoking D2D1CreateFactory function causing created objects to be incompatible. So instead of creating another factory you should query factory corresponding to device context using ID2D1Resource::GetFactory.

answered on Stack Overflow Dec 22, 2019 by user7860670

User contributions licensed under CC BY-SA 3.0