Handmade Network»Forums
8 posts
GUI application rendering and font loading issue
Edited by sam_windell on
I have released a cross platform desktop application whose GUI is rendered with nanovg, using OpenGL 2. On the whole this has been a great success. However, there has been a couple of users who have had issues with it. More specifically they use windows 7 with what I believe is Intel integrated graphics.

My code is structured so that nanovg can be swapped out quite easily, so I have played around with the Windows API, Direct2D/DirectWrite as I think this will be more likely better supported, and should be have good performance. Most functionality is pretty reasonable: drawing rects, arcs, gradients, etc. But the DirectWrite side of things seems super complicated. Here is one of windows samples for loading a ttf font...

I need to load a ttf font from a block of memory I give to it. Does anyone have any experience with this? Or recommend anything else to fix this issue in general?
Mārtiņš Možeiko
2562 posts / 2 projects
GUI application rendering and font loading issue
DirectWrite is not easy to use API, but it should be capable of doing what you want.

To load fonts from memory, you can use IDWriteInMemoryFontFileLoader interface. It will return IDWriteFontFile object that you can pass to IDWriteFactory::CreateFontFace to create actual IDWriteFontFace object.
8 posts
GUI application rendering and font loading issue
Thanks for the suggestion about the font loader interface. Just to update this thread in case others have a similar situation - in the end DirectWrite was not the solution I used. I spent quite a bit of time with the DirectWrite documentation and Microsoft example code - it really is not easy to use at all. If you want something that will easily fit in as the windows part of a cross platform solution it is not simple. To render my GUI I now use the structs ImDrawList, ImFont and ImFontAtlas from the the library 'dear imgui'. These can be quite easily separated from the ImGui code. They seem to be pretty performant, and the backend can easily be switched to OpenGL or DirectX or others.