Hi all,
I've been playing around with D2D and Directwrite, to add text rendering in my 3d engine/ framework.
Using system fonts all works fine, by loading them up using directwrite factory -> CreateTextFormat("font name", nullptr...) etc.
But now I'd also like to load in an external truetype font file (TTF), also using DirectWrite. After trying a lot of options and looking at examples, I just can't figure out how to turn a TTF font file into a usable custom font collection (which I can then use in CreateTextFormat).
Below are some snippets of things I'm trying.
Any hints what I should look for/ try, are appreciated.
std::wstring fontFilename = L"WESTTEST.TTF";
CComPtr<IDWriteFontFile> tFontFile = NULL;
m_dwFactory->CreateFontFileReference(fontFilename.c_str(), NULL, &tFontFile);
IDWriteFontFile* fontFileArray[] = {tFontFile};
CComPtr<IDWriteFontFileLoader> fontFileLoader;
m_dwFactory->RegisterFontFileLoader(fontFileLoader);
int tkey = 3;
m_dwFactory->CreateCustomFontFileReference(&tkey, sizeof(int), fontFileLoader, &tFontFile);
CComPtr<IDWriteFontCollectionLoader> fontCollLoader;
m_dwFactory->RegisterFontCollectionLoader(fontCollLoader);
m_dwFactory->CreateCustomFontCollection(fontCollLoader, &tkey, sizeof(int), &m_dwFontColl);
// continue - working code
HRESULT result = m_dwFactory->CreateTextFormat(L"Arial", nullptr, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, 14.0f, L"", &m_dwFormat);