Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you draw text in DirectX 12?

This is a follow-up question of How do you draw text in DirectX 11?

In Direct3D-12, things got much more complex and since it's new I couldn't find any suitable libraries online.

I'm building a basic Direct3D12 FPS Test application, and I like to display the FPS data on screen with my rendered image.

like image 273
ngub05 Avatar asked Dec 24 '22 07:12

ngub05


2 Answers

The general answer to questions like this is "if you have to ask, then you probably should be using DirectX 11." DirectX 12 is a graphics expert API that provide immense control, and is not particularly concerned with ease-of-use for novices. See this thread for more thoughts in this vein.

With that out of the way, one option is to use device interop and Direct2D/DirectWrite. See Working with Direct3D 11, Direct3D 10 and Direct2D.

UPDATE: DirectX Tool Kit for DirectX 12 is now available. It includes a SpriteFont / SpriteBatch implementation that will draw text on Direct3D 12 render targets. See this tutorial.

like image 128
Chuck Walbourn Avatar answered Jan 17 '23 15:01

Chuck Walbourn


Pure DirectX 12, then you need to load the font glyph data into a vertex buffer and render with a vertex shader and pixel shader. You mentioned libraries online, will this is expert stuff and fortunately James Stanard at Microsoft release a how to with their open source MiniEngine project. He handles multiple fonts, antialiasing, and drop shadows in DirectX 12.

Find the project files at GitHub https://github.com/Microsoft/DirectX-Graphics-Samples/tree/master/MiniEngine and check out Textrender.h and Textrender.cpp

like image 27
Chris Avatar answered Jan 17 '23 17:01

Chris