The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
How to render text documents with SDL_TTF?
akastargazer


Joined: 17 Jan 2014
Posts: 13
Location: Yaroslavl, Russia
What could be the general recommendations to render text like this?


As you can see, many font faces and many font sizes used in this text. So, if SDL_TTF powerful enough, which a primary algorythm should I use? Enumerate all the fonts used by a text document and apply TTF_OpenFont for every of them?

Bring any idea, please.
How to render text documents with SDL_TTF?
javierecf


Joined: 21 Feb 2014
Posts: 52
If you dont want to create a text editor, like editing and selecting, only display, you can keep the different fonts on a separate array and split the char* text of the whole thing according to its style, and then apply every font to each chunk of strings. You will need some kind of word wraper algorithm to go along this thing that works with the sizes of the surfaces that are gonna be rendered, you are talking about a RichText entitie. No sure what else to say.




2014-05-22 14:09 GMT-06:00 akastargazer:
Quote:
What could be the general recommendations to render text like this?


As you can see, many font faces and many font sizes used in this text. So, if SDL_TTF powerful enough, which a primary algorythm should I use? Enumerate all the fonts used by a text document and apply TTF_OpenFont for every of them?

Bring any idea, please.


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org




--
Javier Flores
Re: How to render text documents with SDL_TTF?
akastargazer


Joined: 17 Jan 2014
Posts: 13
Location: Yaroslavl, Russia
javierecf wrote:
If you dont want to create a text editor, like editing and selecting, only display, you can keep the different fonts on a separate array and split the char* text of the whole thing according to its style, and then apply every font to each chunk of strings. You will need some kind of word wraper algorithm to go along this thing that works with the sizes of the surfaces that are gonna be rendered, you are talking about a RichText entitie. No sure what else to say.
Thank you for response! Yes, a text editor is a main goal. I already have all of the necessary text processing facilites like text wraping, editing and others, and new rendering engine based on SDL. So I'd like to realize how to obtain maximum text rendering performance.
How to render text documents with SDL_TTF?
javierecf


Joined: 21 Feb 2014
Posts: 52
Maybe the best will be to use bitmap files for the fonts and selecting each glyph from the image according the the words and its style.



2014-05-22 14:32 GMT-06:00 akastargazer:
Quote:



javierecf wrote:

If you dont want to create a text editor, like editing and selecting, only display, you can keep the different fonts on a separate array and split the char* text of the whole thing according to its style, and then apply every font to each chunk of strings. You will need some kind of word wraper algorithm to go along this thing that works with the sizes of the surfaces that are gonna be rendered, you are talking about a RichText entitie. No sure what else to say.


Thank you for response! Yes, a text editor is a main goal. I already have all of the necessary text processing facilites like text wraping, editing and others, and new rendering engine based on SDL. So I'd like to realize how to obtain maximum text rendering performance.


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org




--
Javier Flores
How to render text documents with SDL_TTF?
Juan Manuel Borges Caño
Guest

I wonder what is the status or worth working on, SDL_rtf Rich Text Format :-).
mr_tawan


Joined: 13 Jan 2014
Posts: 161
I think it's probably easier to go straigh to use freetype with SDL, rather than using SDL_ttf.
How to render text documents with SDL_TTF?
Jeffrey Carpenter
Guest

Hi there,

SDL_TTF is certainly powerful enough, and can be thought of as a lightweight wrapper for the FreeType2 API. If you can get away with simply caching every font used in the text document, I'd say that you can call it good there, but in any regard, the answer is yes to caching (loading) the fonts ahead of time.

For high performance text rendering, you could create a texture atlas (think: sprite sheet) composed of every glyph in the font(s) loaded, and render text strings from the coordinates of the texture atlas. The performance is great (hundreds of FPS), and the only time that you incur performance hits is when the font's point size (text size) is changed -- you must regenerate the glyph atlas, but you can cache this, too, if necessary. (I don't since I can get away with it). Changing the font's style (bold, italics, underlined) can also incur a small performance penalty, but these can be cached as well.

For an example of using SDL_TTF for generating a texture atlas, check out:

1. https://github.com/i8degrees/nomlib/blob/dev/src/graphics/fonts/TrueTypeFont.cpp#L229
2. https://github.com/i8degrees/nomlib/blob/dev/src/graphics/Text.cpp#L402

I wish you luck! :-)

Cheers,
Jeffrey Carpenter


On 2014/05/ 22, at 15:09, akastargazer wrote:

Quote:
What could be the general recommendations to render text like this?


As you can see, many font faces and many font sizes used in this text. So, if SDL_TTF powerful enough, which a primary algorythm should I use? Enumerate all the fonts used by a text document and apply TTF_OpenFont for every of them?

Bring any idea, please.
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
How to render text documents with SDL_TTF?
Leonardo


Joined: 11 Feb 2010
Posts: 46
Hi. You said that you have wrapping algortihms in place already, but you may want to consider the _Wrapped versions of the usual TTF render calls. They return a single surface. Those methods are not on the docs (I wonder when they'll be documented Smile

Creating a texture atlas of the glyphs may not be what you want if you're creating a text editor because there is a lot going on that is handled by freetype (and hence by SDL_ttf), such as hinting, kerning. For instance, in some fonts, you can see that the when you type the char V and A together (having VA), they may overlap each other (see http://en.wikipedia.org/wiki/Kerning). This is all done by freetype for you. If you're ok with not having kerning, then its ok to have an atlas, I guess.



2014-05-22 18:13 GMT-03:00 Jeffrey Carpenter:
Quote:
Hi there,

SDL_TTF is certainly powerful enough, and can be thought of as a lightweight wrapper for the FreeType2 API. If you can get away with simply caching every font used in the text document, I'd say that you can call it good there, but in any regard, the answer is yes to caching (loading) the fonts ahead of time.

For high performance text rendering, you could create a texture atlas (think: sprite sheet) composed of every glyph in the font(s) loaded, and render text strings from the coordinates of the texture atlas. The performance is great (hundreds of FPS), and the only time that you incur performance hits is when the font's point size (text size) is changed -- you must regenerate the glyph atlas, but you can cache this, too, if necessary. (I don't since I can get away with it). Changing the font's style (bold, italics, underlined) can also incur a small performance penalty, but these can be cached as well.

For an example of using SDL_TTF for generating a texture atlas, check out:

1. https://github.com/i8degrees/nomlib/blob/dev/src/graphics/fonts/TrueTypeFont.cpp#L229
2. https://github.com/i8degrees/nomlib/blob/dev/src/graphics/Text.cpp#L402

I wish you luck! :-)

Cheers,
Jeffrey Carpenter


On 2014/05/ 22, at 15:09, akastargazer wrote:

Quote:
What could be the general recommendations to render text like this?



Quote:
As you can see, many font faces and many font sizes used in this text. So, if SDL_TTF powerful enough, which a primary algorythm should I use? Enumerate all the fonts used by a text document and apply TTF_OpenFont for every of them?

Bring any idea, please.

Quote:
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


How to render text documents with SDL_TTF?
Jeffrey Carpenter
Guest

Leonardo,

You remind me of a curious question I have with SDL_ttf. There exists a TTF_GetKerningSize function as of the last release, although I have yet to ever see a non-zero value from it, from any of the fonts that I've tried (admittedly, only Minion Pro, Arial and Times New Roman), with kerning explicitly enabled, rendering the whole ASCII glyph set. I suppose that my real question might be, what fonts should I expect to see a non-zero kerning value?

Glancing through the SDL_ttf.c, it would lead me to believe that kerning *is* supported, but my tests seem to say otherwise. So, either my testing methodology is flawed, or SDL_ttf does not support kerning (possible bug within the API?)

If the kerning API in SDL_ttf does work, then applying kerning to the rendered string of glyphs is trivial.

Cheers,
Jeffrey Carpenter


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
How to render text documents with SDL_TTF?
Juan Manuel Borges Caño
Guest

The backend is FreeType, http://www.freetype.org/freetype2/docs/glyphs/glyphs-4.html , look at the BRAVO example.  http://www.freetype.org/freetype2/docs/tutorial/step2.html , simple kerning, then, advaced. This corner of the Internet explains text composition very detailedly; from implentators.
Again, makes more sense to me to use SDL_rtf, else, for the work and benefits you might as well program a GTK or QT,... SDL backend Wink.
It finally works!
akastargazer


Joined: 17 Jan 2014
Posts: 13
Location: Yaroslavl, Russia
Look at this! I'm very happy to show results of work. SDL + SDL_TTF + BlackBox Component Builder.



And screencast here: http://youtu.be/Sn1rEmwHX5U
How to render text documents with SDL_TTF?
Jeffrey Carpenter
Guest

Beautiful! Very Happy

Cheers,
Jeffrey Carpenter


On 2014/09/ 23, at 8:02, akastargazer wrote:

Quote:
Look at this! I'm very happy to show results of work. SDL + SDL_TTF + BlackBox Component Builder.



And screencast here: http://youtu.be/Sn1rEmwHX5U
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org