You confuse the use of D2D1CreateFactory
and DWriteCreateFactory
.
D2D1CreateFactory
is used to create the ID2D1Factory
interface, which is used to create an ID2D1HwndRenderTarget
and an ID2D1SolidColorBrush
to render text.
DWriteCreateFactory
is used to create an IDWriteFactory
interface, which is the root factory interface for all DirectWrite
objects. And the DirectWrite
objects are used to format the text.
Such as:
ID2D1HwndRenderTarget* pRT_;
...
pRT_->DrawText(
wszText_, // The string to render.
cTextLength_, // The string's length.
pTextFormat_, // The text format.
layoutRect, // The region of the window where the text will be rendered.
pBlackBrush_ // The brush used to draw the text.
);
Maybe you can start from Part 2: Create Device Independent Resources.
Some code:
IDWriteFactory* pDWriteFactory_;
hr = DWriteCreateFactory(
DWRITE_FACTORY_TYPE_SHARED,
__uuidof(IDWriteFactory),
reinterpret_cast<IUnknown**>(&pDWriteFactory_)
);
...
if (SUCCEEDED(hr))
{
// Create a DirectWrite text format object.
hr = pDWriteFactory_->CreateTextLayout(
L"Projects", // The string to be laid out and formatted.
8, // The length of the string.
writeTextFormat, // The text format to apply to the string (contains font information, etc).
10.0f, // The width of the layout box.
10.0f, // The height of the layout box.
&writeTextLayout // The IDWriteTextLayout interface pointer.
);
}
Official example: HelloWorld
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…