[英]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. 我可以在SharpDX文字周围画出笔画,但是速度很慢。
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? 还有其他解决方案可以围绕文本绘制相同内容吗?
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 在那里,您会发现诸如轮廓,发光,阴影等文本效果: https : //steamcdn-a.akamaihd.net/apps/valve/2007/SIGGRAPH2007_AlphaTestedMagnification.pdf
libgdx implementation of SDF can be used as the reference. SDF的 libgdx实现可以用作参考。 You can find it here: https://github.com/libgdx/libgdx/wiki/Distance-field-fonts 您可以在这里找到它: https : //github.com/libgdx/libgdx/wiki/Distance-field-fonts
Implementation of SDF requires some knowledge of shaders programming. SDF的实现需要一些着色器编程知识。 Hope my answer helps 希望我的回答有帮助
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. 我正在使用Codehead的位图字体生成器来使用纹理渲染我的自定义渲染器。 This is for DirectX 11 Direct3d. 这是针对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. 通常,着色器将是1到1像素的渲染,但是在这种情况下,您希望使用其他颜色对纹理进行边缘处理。 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. 为此,我使用了“百分比更近过滤器”算法,该算法基本上对5个点进行采样,每个方向上的1个像素加上中心。 if I get 1 black pixel returned in any direction then I have hit an edge and colour accordingly. 如果我在任何方向都得到了1个黑色像素,则我碰到了边缘并相应地上色了。 There are much better versions of this out here, but that's how I approached it. 这里有很多更好的版本,但这就是我的解决方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.