4

Man so much has changed since I learned DirectX 7.

Everywhere I look (except Wikipedia), it says I have to render from DWrite to D2D or GDI before I can do anything.

Is that Wikipedia article wrong? Can I not render to Direct3D?

I'd like to avoid having to render to D2D, since apparently, to get D2D to write to D3D, you have to open up a D3D10.1 device as well.

Does it really take all this just to render text in D3D11?

Charles
  • 50,943
  • 13
  • 104
  • 142
Rei Miyasaka
  • 7,007
  • 6
  • 42
  • 69

1 Answers1

2

Unfortunately, Microsoft decided to remove native text support from their DirectX API. Now you can either use DirectWrite, and then as you said render to GDI or D2D, which is somewhat clunky, or alternatively, make your own font-handling class, and use that (which is what I've chosen to done for my project).

There is a good tutorial on how to produce a custom Font-handling class, here: http://www.rastertek.com/dx11tut12.html

Obviously, you should write your own, but it provides a good starting point, and allows you to see all the necessary proceedures (something you will probably want to add will be support for multiple fonts, for which I recommend creating a Font class, which your Font-Handler stores with an associative string in a std::map< char*, Font* >).

Hope this helps! :)

Thomas Russell
  • 5,870
  • 4
  • 33
  • 68
  • Thanks Shaktal. So to get from D2D to D3D11, do I still have to go through D3D10.1? – Rei Miyasaka Jul 24 '11 at 21:46
  • You can use the DXGI packaged with D3D10 to get a IDXGISurface and then you can use this as a RT for D2D through invoking CreateDxgiSurfaceRenderTarget. You can find lots more information about using it, [here](http://msdn.microsoft.com/en-us/library/dd370966(v=vs.85).aspx). Unfortunately, we need to get our D3D10.1 device and then blend the D2D information to our buffer after rendering our 3D scene. This is an awful way of doing it, but microsoft are aware of the issue, and presumably they will re-add ID3D10Font in the future. But for now creating your own font-handler is the optimal way! :) – Thomas Russell Jul 24 '11 at 21:54
  • Bah. Well people have been talking about it since 2009, so I bet it'll take until at least DirectX12 before they put it back in. I'd like to say I could just make my own sprite-based font solution, but that's a bit impractical for East-Asian languages, which have thousands of glyphs. I guess I'll have to go through D3D10.1. – Rei Miyasaka Jul 24 '11 at 22:03
  • Yeah, I think they'll probably wait till DirectX 12 before they create ID3D12Font (or whatever they call their interface). Is it necessary for each of those characters to be in-game? Or are you having a feature whereby players can talk to other players? Else you could have an artist driven font system, where you request a character from your artist (or make it yourself) as you find you need it? – Thomas Russell Jul 24 '11 at 22:07
  • Neither, to be honest. There isn't anything particularly important that I'm doing. I've been in a slump lately so I've been relearning D3D to try to feel better about myself. I remembered text rendering to be a lot easier than it is now, so I thought maybe I was doing something wrong. – Rei Miyasaka Jul 24 '11 at 22:58