Jump to content
  • Advertisement
Sign in to follow this  
schupf

Text Rendering without D3DX

This topic is 2591 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

[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/

Share this post


Link to post
Share on other sites

[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?

Share this post


Link to post
Share on other sites

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

Share this post


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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!