Direct2d/directwrite with DX11

Started by
5 comments, last by cozzie 5 years, 12 months ago

Hi all,

As a part of the debug drawing system in my engine,  I want to add support for rendering simple text on screen  (aka HUD/ HUD style). From what I've read there are a few options, in short:

1. Write your own font sprite renderer
2. Using Direct2D/Directwrite, combine with DX11 rendertarget/ backbuffer
3. Use an external library, like the directx toolkit etc.

I want to go for number 2, but articles/ documentation confused me a bit. Some say you need to create a DX10 device, to be able to do this, because it doesn't directly work with the DX11 device.  But other articles tell that this was 'patched' later on and should work now.

Can someone shed some light on this and ideally provide me an example or article on  how to set this up?

All input is appreciated.

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

Advertisement

D2D works with D3D10 or D3D11 on Windows 8, or the Platform Update for Windows 7 (KB2670838). All of the D2D interfaces take IDXGI* interfaces, which can be retrieved from either D3D10 or 11.

This dx10 page describes using dx2d in dx3d https://msdn.microsoft.com/en-gb/library/windows/desktop/dd370966(v=vs.85).aspx

You can do the same things in dx11 using your standard dx11 device instead of using the dx10 one they created on that page

It describes both

1) writing to the swapchain

2) writing to a texture that you use from your standard d3d code.

I used it for the 2nd application in dx11.

I created my factory using D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &pD2DFactory);

One gotcha you have to watch out for is dx2d prefers textures in the format BGRA rather than RGBA. I dont know why.

 

Thanks both, then I'm going for option 2 and will look into the example(s).

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

There is another method to make text on screen -

You use dx2d to write text to a texture then use d3d to draw a square or rectangle on the screen using that texture.

The advantages of this way over writing text to the back buffer are:

1. you dont have to use the dx2d writing every frame. Good if you have large amounts of text on complex dialogs.

2. you dont have to change the texture format of your swapchain to BGRA. You simply have to have that one texture that gets written to by dx2d have this format.

I use this method on my dialog boxes that the user can drag around the screen like windows.

Just for future reference/ if someone wants to do the same, this 'Sweet snipper' from Washu really helped me out:

 

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

This topic is closed to new replies.

Advertisement