Jump to content
  • Advertisement
Sign in to follow this  
cozzie

DX11 Direct2d/directwrite with DX11

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Posted (edited)

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.

 

Edited by CortexDragon

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Posted (edited)

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.

Edited by CortexDragon

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!