Sign in to follow this  
schupf

Text Rendering without D3DX

Recommended Posts

schupf    221
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!

Share this post


Link to post
Share on other sites
Krohm    5031
You might want to consider this thread:
[url="http://www.gamedev.net/topic/596885-block-of-text/"]Block of text (clicky)[/url]

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

Share this post


Link to post
Share on other sites
Flimflam    665
[url="http://www.angelcode.com/products/bmfont/"]http://www.angelcode.com/products/bmfont/[/url]

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.

Share this post


Link to post
Share on other sites
Evil Steve    2017
[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.[/quote]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.

Share this post


Link to post
Share on other sites
ryan20fun    2635
[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?).
[/quote]

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

Share this post


Link to post
Share on other sites
NightCreature83    5006
[quote name='ryan20fun' timestamp='1305538427' post='4811364']
[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?).
[/quote]

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/

Share this post


Link to post
Share on other sites
Icebone1000    1958
[quote name='Evil Steve' timestamp='1305534841' post='4811349']
[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.[/quote]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?

Share this post


Link to post
Share on other sites
MickeyMouse    201
[quote name='Icebone1000' timestamp='1305603784' post='4811761']
Anyway, should I use instancing for rendering texture fonts?

[/quote]

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

Share this post


Link to post
Share on other sites
MJP    19791
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.

Share this post


Link to post
Share on other sites
Krohm    5031
[quote name='Icebone1000' timestamp='1305603784' post='4811761']Anyway, should I use instancing for rendering texture fonts?[/quote]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 [b]use the easier method that meets the wanted performance.[/b]
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.

Share this post


Link to post
Share on other sites
Icebone1000    1958
My lac of experience with intancing dont let me find alternatives for drawing sprites or texts..
Im currently batching everything, the only thing I have to update is a scaling factor, a world matrix( in the case of fonts means spacing and new lines) and an uv offset trough a constant buffer. The problem just comes for sprites that use different UVs, then I have to update the VB only because of the UVs..

Theres a way to "group" instances?
Lets say I have a Vertex buffer with UV of:
U = 1/16, V = 3/16 #this is my font sprites, lets say I have 2 fonts(texture, sprite sheet) that use this same VB.

Can I draw 25 characters using one font, and 100 using the other, with a single draw call?(each character needs a new position and a new UV offset, but the first 25 dont need a new shader resource view, and the later 100 also uses the same font, can I instance all that without having to pass 25 times the same texture, and 100 times the other texture on a texture array?)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this