Text Rendering without D3DX

Started by
9 comments, last by Icebone1000 12 years, 11 months ago
Hello,

I want to render text in a Direct3D9 application and I don't want to use D3DX (btw: would D3DX lib be available on Xbox360?). I have seen some people recommending using one polygon

fore each glpyh and assign texture coordinates to a "glyph texture atlas" (a texture that contains all letters ABCDE.. etc).

But with all the settings (font size, bold etc) this seems very tedious to me. Are there some Code samples/tutorials available? I mean this must be a common problem. Or are there any other solutions?




Thanks!

Advertisement
You might want to consider this thread:
Block of text (clicky)

Yes, what you say it's tedious.
Yes, there are alternatives.
Choose your destiny...

Previously "Krohm"

http://www.angelcode.com/products/bmfont/

This is what I personally use. It will output textures and a character information file for all the glyphs in the font you choose to export. Then you just write the draw code.

I have seen some people recommending using one polygon fore each glpyh and assign texture coordinates to a "glyph texture atlas" (a texture that contains all letters ABCDE.. etc).

But with all the settings (font size, bold etc) this seems very tedious to me.
Most games don't use 100 different fonts - they have a few different fonts that they use - in which case pre-generating them isn't a big deal. Another option is to generate the font texture from within your application - then the user can change the font face, size, format, etc from within the game, and you just need to regenerate the fonts - but that's quite a bit more work.
Personally, I generate my fonts offline and then draw them with one quad per glyph, as you suggested.

Hello,

I want to render text in a Direct3D9 application and I don't want to use D3DX (btw: would D3DX lib be available on Xbox360?).


the Xbox360 is based on DirectX, besides why wouldi have predefined swithces for XBOX with C++ and DirectX.
but it only supports upto DX9.0c

Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.


[quote name='schupf' timestamp='1305454309' post='4811015']
Hello,

I want to render text in a Direct3D9 application and I don't want to use D3DX (btw: would D3DX lib be available on Xbox360?).


the Xbox360 is based on DirectX, besides why wouldi have predefined swithces for XBOX with C++ and DirectX.
but it only supports upto DX9.0c
[/quote]
Actually that is not true the X360 supports more then DX9.0c it has some features that are present in DX9.0L, which is a few features that are mandatory for DX10. D3DX is present in the X360 XDK, but to develop for this you need access to a DevKit and the XDK which are expensive.

The only other option on X360 is C# and XNA which is only DX9.0c and is available to everyone/

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion


[quote name='schupf' timestamp='1305454309' post='4811015']
I have seen some people recommending using one polygon fore each glpyh and assign texture coordinates to a "glyph texture atlas" (a texture that contains all letters ABCDE.. etc).

But with all the settings (font size, bold etc) this seems very tedious to me.
Most games don't use 100 different fonts - they have a few different fonts that they use - in which case pre-generating them isn't a big deal. Another option is to generate the font texture from within your application - then the user can change the font face, size, format, etc from within the game, and you just need to regenerate the fonts - but that's quite a bit more work.
Personally, I generate my fonts offline and then draw them with one quad per glyph, as you suggested.
[/quote]


Instancing?
Im current calling a draw call per letter, seems terrible, but works like a charm..
I tried to implement instancing, so Id send all positions and UVs per char at once, but I started to realize it requires much more work to do that then calling a draw call per letter, like having a max number of chars to create an array on the shaders, and youd have to allocate, depending on the string size, a buffer(on cpu) to fill the uvs, or have one with the max number of letters possible(wasting space)..it just started to get too ugly..and at the end I got lots of problems( I think it was due data alignment between visual studio and hlsl), and them I gived up >_>"...I still didnt manage to get any instancing try working with shaders u_u**

Anyway, should I use instancing for rendering texture fonts?


Anyway, should I use instancing for rendering texture fonts?



I don't use instancing to draw fonts but it certainly might be a good option.

What I do is:
- create "dummy" static index buffer with indices for consecutive quads, i.e. (0,1,2),(0,2,3),...
- create dynamic vertex buffer for allocating quads used to draw characters - treat it as a ring buffer (on DX make use of discard functionality)
- every time I draw some text:
(a) allocate chunk of vertex buffer of size 4 * text-length * sizeof(vertex) and set up data for all verts
(b) bind index & vertex buffers
(c ) indexed draw
Maciej Sawitus
my blog | my games
Yeah definitely want to minimize your draw calls. Instancing is fine for that, unless you don't want to support lower than SM3.0-level GPU's. In which case just using a dynamic vertex buffer should serve you well.
Anyway, should I use instancing for rendering texture fonts?
In my opinion, you shouldn't. Most of the letters don't change in position with regard to others. Just pre-transform them.

Even in the case of tens of thousands letters, I haven't found text drawing to be a performance problem so use the easier method that meets the wanted performance.
But, if performance is your concern, then pre-transforming them will possibly go even faster. I don't think you will be able to measure any benefit. Especially if you already do one batch per glyph - this implies your text is small compared to your available CPU power, which implies you're taking wrong measurements.

Pre-transforming has a few advantages, especially if selecting is required. Put the batch in "sheet space" and then use a VS to xform the "sheet space" in world space.
The main drawback is the amount of work to deal with changing text. I haven't dealt with this problem in detail, nor I plan to in medium term.

Previously "Krohm"

This topic is closed to new replies.

Advertisement