Jump to content
  • Advertisement
Sign in to follow this  
QQemka

DX11 So How Do I Render Font? (Dx11)

This topic is 801 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello. I've been searching for quite some time for replacement of d3d9 font interface in dx11. Sadly such thing does not exist, and so i have a lot to choose from. GDI, Direct2D shared surfaces, and the font textures with given uv for every letter. I would like to ask several questions before i actually do coding, to be sure i am not doing it wrong :)

 

From what i read and saw in tuts, GDI and Direct2D is pain to set up with all that shared surfaces, and they reduce performance significantly,  but they offer convenient function which takes const char* and print the text.

 

The second option, with font texture works just like any other texture, but should be used with ortho matrix to render in 2d. But now i have to print letter by letter and I am afraid I dont know how to do it efficiently (i speak about sending data to gpu right now).

I will have to constantly update x and y location for every letter in every sentence to be printed? I assume no kerning, every letter got the same fixed size, like in visual studio or notepad. So i have to somehow be able to send variadic ammount of letters to vertex shader (or assume max sentence size) but I cant really "see it".

 

How do i make it work without making it too heavy?
Greetz

Share this post


Link to post
Share on other sites
Advertisement

It's probably faster than an unoptimized hand-rolled font texture implementation, but slower than one that's optimized for your specific scenario. Instead of asking if it's fast enough, try it out and see if it's fast enough for your purposes?

Share this post


Link to post
Share on other sites

Im implementing it at the moment. Well, i will have to print out chat box every frame, characters stats etc. Its not too much, but its not little either. I will report back soon :)

Share this post


Link to post
Share on other sites

DirectWrite ought to be plenty fast unless you find a performance hole to step in, its used pretty extensively throughout Windows 10 for text rendering.

Share this post


Link to post
Share on other sites

I am reading thorugh braynzarsoft tutorial. There is so much stuff just to render the font

ID3D10Device1 *d3d101Device;
IDXGIKeyedMutex *keyedMutex11; 
IDXGIKeyedMutex *keyedMutex10; 
ID2D1RenderTarget *D2DRenderTarget; 
ID2D1SolidColorBrush *Brush; 
ID3D11Texture2D *BackBuffer11; 
ID3D11Texture2D *sharedTex11; 
ID3D11Buffer *d2dVertBuffer; 
ID3D11Buffer *d2dIndexBuffer; 
ID3D11ShaderResourceView *d2dTexture; 
IDWriteFactory *DWriteFactory;
IDWriteTextFormat *TextFormat;

Is it REALLY that much required to have directwrite working?

Share this post


Link to post
Share on other sites

When i wrote that tutorial, dx11 was not directly compatible with d2d, and you had to create a d3d10 device to work with d2d.

 

Since d3d 11.1 came out, you don't need to create a d3d 10 device from what i understand, and d3d 11 working with d2d is much easier, so i would not suggest following that tutorial for rendering text sadly

Edited by iedoc

Share this post


Link to post
Share on other sites

I noticed that most of these things are no longer necessary :) You are the most helpful person on the internet sir :)

Share this post


Link to post
Share on other sites

DirectDraw works ALMOST fine. The DrawText method asks for rectanlge to render the text in, but when the text is too long it renders in newline, or even goes out of bounds... Is there any way to prevent it?

 

bAmZPoQ.png

 

 

I set box with 50 width,height. Can i somehow force the draw to stop drawing out of box?

Thats the code

void Font::Draw(const wchar_t* text, float left, float top, float right, float bottom)
{
    d2dRenderTarget->BeginDraw();
    d2dRenderTarget->DrawTextW(text, wcslen(text), textFormat, D2D1::RectF(left, top, right, bottom), brush);
    d2dRenderTarget->EndDraw();
}

Oh i did not notice default parameters in DrawtextW.... :)

typedef enum  { 
  D2D1_DRAW_TEXT_OPTIONS_NO_SNAP            = 0x00000001,
  D2D1_DRAW_TEXT_OPTIONS_CLIP               = 0x00000002,
  D2D1_DRAW_TEXT_OPTIONS_NONE               = 0x00000000,
  D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT  = 0x00000004
} D2D1_DRAW_TEXT_OPTIONS;

Now it clips

Edited by QQemka

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!