Reputation: 149
I am able to draw stroke around the text in sharpDX but it is very slow.
Here is my code:
d2dRenderTarget.DrawTextLayout(new Vector2(298, 300), textLayout0, textBrush1,DrawTextOptions.NoSnap);
d2dRenderTarget.DrawTextLayout(new Vector2(302, 300), textLayout0, textBrush1, DrawTextOptions.NoSnap);
d2dRenderTarget.DrawTextLayout(new Vector2(300, 302), textLayout0, textBrush1, DrawTextOptions.NoSnap);
d2dRenderTarget.DrawTextLayout(new Vector2(300, 298), textLayout0, textBrush1, DrawTextOptions.NoSnap);
d2dRenderTarget.DrawTextLayout(new Vector2(300, 300), textLayout0, textBrush, DrawTextOptions.NoSnap);
Here is my output:
Is there anyother solution to draw same thing around text?
Upvotes: 1
Views: 1119
Reputation: 345
Distance Field Fonts perhaps is what you are looking for. It is the fast and qualitative technique of rendering super-smooth scalable bitmap fonts.
Take a look at it in this document; there you will find such text effects like outlining, glow, drop shadow: https://steamcdn-a.akamaihd.net/apps/valve/2007/SIGGRAPH2007_AlphaTestedMagnification.pdf
libgdx implementation of SDF can be used as the reference. You can find it here: https://github.com/libgdx/libgdx/wiki/Distance-field-fonts
Implementation of SDF requires some knowledge of shaders programming. Hope my answer helps
Upvotes: 2
Reputation: 444
I will give you a quick run down and how I attacked it, this will most likely not fit at all with your current implementation. But i found faster.
I'm using Codehead's bitmap font generator to use textures to render my custom renderder. This is for DirectX 11 Direct3d. I then renderer these as tiles onto the screen in screen space. Normally, the shader would be a 1 to 1 pixel render, in this case though, you're wanting to edge your texture with a different colour. This in itself is similar to an anti aliasing technique. For this, I use a "Percentage Closer Filter" algorithm which basically samples 5 points, 1 pixel in each direction plus the centre. if I get 1 black pixel returned in any direction then I have hit an edge and colour accordingly. There are much better versions of this out here, but that's how I approached it.
Upvotes: 0