简体   繁体   English

如何在DirectX 9中尽快使用D3DXSprite绘制D3DXFont?

[英]How to draw D3DXFont using D3DXSprite in DirectX 9 as fast as possible?

I have lots of text to draw. 我有很多文字要画。 If I call D3DXFont::DrawText with first parameter being NULL I get terrible performance. 如果我用第一个参数为NULL调用D3DXFont :: DrawText,则性能会很差。

I heard that using D3DXFont with conjunction with D3DXSprites makes things much more faster. 我听说将D3DXFont与D3DXSprites结合使用会使事情变得更快。

How my application needs to draw strings? 我的应用程序需要如何绘制字符串? It daraws every string with pseudo shadow. 它使用伪阴影使每个字符串不正确。 It means I draw each string 4 times in black: x + 1, y + 1 x - 1, y + 1 x - 1, y - 1 x + 1, y - 1 and 1 time in actual color. 这意味着我将每个字符串以黑色绘制4次:x + 1,y + 1 x-1,y + 1 x-1,y-1 x + 1,y-1和1次以实际颜色绘制。 It makes very nice looking always readable strings. 它使始终可读的字符串看起来非常漂亮。 I even switched to pixel fonts for faster rendering. 我什至切换到像素字体以加快渲染速度。

Now call that string with shadow (ShadowString). 现在用阴影(ShadowString)调用该字符串。

Every frame I draw 256 (worst case scenario) of those ShadowStrings on screen. 我每画一帧都会在屏幕上绘制256个ShadowString(最坏的情况)。

I would like to know how to use sprites (or any other technique) to speed up drawing of those string as much as possible). 我想知道如何使用子画面(或任何其他技术)来尽可能快地绘制这些字符串)。 Now I'm getting 30 FPS in app. 现在我的应用程序速度为30 FPS。 But I target for 120 min. 但我的目标是120分钟。 And problem is ONLY that text drawing thing. 而问题仅在于文本绘图。

Surely, you must profile your application before any optimizations, but truth to be told, D3DXFont / D3DXSprites and "fast" is mutually exclusive concepts. 当然,您必须在进行任何优化之前就对应用程序进行概要分析,但是D3DXFont是, D3DXFont / D3DXSprites和“ fast”是互斥的概念。 If they do not fit, just don't use them. 如果它们不合适,那就不要使用它们。 Use 3rd party libraries or make your own sprite/font renderer. 使用第三方库或制作自己的精灵/字体渲染器。

Recently I've answered about how to do it here: How to draw line and font without D3DX9 in DirectX 9? 最近,我在这里回答了如何操作: 在DirectX 9中如何在没有D3DX9的情况下绘制线条和字体? Also, Google for "sprite font", "sprite batching", "texture atlases", "TTF rendering". 此外,Google用于“精灵字体”,“精灵批处理”,“纹理图集”,“ TTF渲染”。 It is not very difficult if you are familiar with API (notably vertex buffers and texturing), and there are plenty of examples on web. 如果您熟悉API(尤其是顶点缓冲区和纹理),这并不是很难,而且Web上有很多示例。 Don't hesitate to look for D3D11 or OpenGL examples, principles are the same. 不要犹豫,寻找D3D11或OpenGL示例,原理是相同的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM