Faisal
Faisal

Reputation: 149

Fastest way to to draw stroke/outline around text in SharpDX c#?

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:

enter image description here

Is there anyother solution to draw same thing around text?

Upvotes: 1

Views: 1119

Answers (2)

Yurii S
Yurii S

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.

Implementation of SDF requires some knowledge of shaders programming. Hope my answer helps

Upvotes: 2

ErnieDingo
ErnieDingo

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

Related Questions