Generating text surfaces in a main loop

Hello,

It is said on a lot of topics, web pages that generating texts with SDL_ttf
in blended mode is very slow. In my game, I would like to create a menu
with some font surfaces.

There is no problem using TTF_RenderUTF8_Blended. But I would like to add a
glowing effect, to show which menu entry is currently selected.

What I would like to do if possible, generating a text surface in any
colour you like and then apply some color or mask to alter the surface
colors, but I don’t know at all how to do that and if it’s possible.

So my questions are :

  1. Can I just call TTF_RenderUTF8_Blended in my main loop or it is very
    discouraged?
  2. If not how can I alter the surface color to get a blinking effect.

Cheers,–
Demelier David

What version of SDL are you using? SDL 2 has
SDL_SetSurfaceColorModhttp://wiki.libsdl.org/moin.cgi/SDL_SetSurfaceColorModand
SDL_SetTextureColorMod
http://wiki.libsdl.org/moin.cgi/SDL_SetTextureColorModwhich may help
(they change the color of your text - just make sure it’s white first). If
you need to do an effect that depends on the actual text displayed (like
blurred glowing text behind the original text), you’re best off with using
OpenGL directly and probably writing a shader to do the work.

TTF_RenderUTF8_Blended will be fine in some apps, but very slow in others.
It really depends on how you use it and how much text is being rendered.
You should cache the results of the rendering wherever possible. In my
projects, I’ve been dragging along a caching class that you’re welcome to
(no guarantees :).

Jonny DOn Tue, Feb 12, 2013 at 8:24 AM, David Demelier <demelier.david at gmail.com>wrote:

Hello,

It is said on a lot of topics, web pages that generating texts with
SDL_ttf in blended mode is very slow. In my game, I would like to create a
menu with some font surfaces.

There is no problem using TTF_RenderUTF8_Blended. But I would like to add
a glowing effect, to show which menu entry is currently selected.

What I would like to do if possible, generating a text surface in any
colour you like and then apply some color or mask to alter the surface
colors, but I don’t know at all how to do that and if it’s possible.

So my questions are :

  1. Can I just call TTF_RenderUTF8_Blended in my main loop or it is very
    discouraged?
  2. If not how can I alter the surface color to get a blinking effect.

Cheers,


Demelier David


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

2013/2/12 Jonathan Dearborn

What version of SDL are you using? SDL 2 has SDL_SetSurfaceColorModhttp://wiki.libsdl.org/moin.cgi/SDL_SetSurfaceColorModand SDL_SetTextureColorMod
http://wiki.libsdl.org/moin.cgi/SDL_SetTextureColorModwhich may help
(they change the color of your text - just make sure it’s white first). If
you need to do an effect that depends on the actual text displayed (like
blurred glowing text behind the original text), you’re best off with using
OpenGL directly and probably writing a shader to do the work.

Thanks for your quick answer, I’m using SDL 1.2.15.

I don’t know OpenGL at all, I will need to learn everything to use OpenGL
and rewrite everything since my game is 2D only :-(.

TTF_RenderUTF8_Blended will be fine in some apps, but very slow in others.
It really depends on how you use it and how much text is being rendered.
You should cache the results of the rendering wherever possible. In my
projects, I’ve been dragging along a caching class that you’re welcome to
(no guarantees :).

Yes actually I had some code that regenerate the text surface only if menu
entry has changed or if the color has been updated (by time interval) and
that gone very messy and hard to maintain. That’s why I asked for a better
solution.

David.> Jonny D

On Tue, Feb 12, 2013 at 8:24 AM, David Demelier <@David_Demelier>wrote:

Hello,

It is said on a lot of topics, web pages that generating texts with
SDL_ttf in blended mode is very slow. In my game, I would like to create a
menu with some font surfaces.

There is no problem using TTF_RenderUTF8_Blended. But I would like to add
a glowing effect, to show which menu entry is currently selected.

What I would like to do if possible, generating a text surface in any
colour you like and then apply some color or mask to alter the surface
colors, but I don’t know at all how to do that and if it’s possible.

So my questions are :

  1. Can I just call TTF_RenderUTF8_Blended in my main loop or it is very
    discouraged?
  2. If not how can I alter the surface color to get a blinking effect.

Cheers,


Demelier David


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Demelier David

Well, in that case, you should just keep it simple. Work with what you
have and don’t worry too much about being unable to do certain effects.
Try using SDL_ttf directly without caching and see how well it works. If
it’s just for menus, then there should be no problem at all. You can also
try different effects. A common and simple one is a “glow” surface that is
stretched to the width of your menu items and drawn behind them as a
highlight.

Jonny DOn Tue, Feb 12, 2013 at 10:07 AM, David Demelier <demelier.david at gmail.com>wrote:

2013/2/12 Jonathan Dearborn <@Jonathan_Dearborn>

What version of SDL are you using? SDL 2 has SDL_SetSurfaceColorModhttp://wiki.libsdl.org/moin.cgi/SDL_SetSurfaceColorModand SDL_SetTextureColorMod
http://wiki.libsdl.org/moin.cgi/SDL_SetTextureColorModwhich may help
(they change the color of your text - just make sure it’s white first). If
you need to do an effect that depends on the actual text displayed (like
blurred glowing text behind the original text), you’re best off with using
OpenGL directly and probably writing a shader to do the work.

Thanks for your quick answer, I’m using SDL 1.2.15.

I don’t know OpenGL at all, I will need to learn everything to use OpenGL
and rewrite everything since my game is 2D only :-(.

TTF_RenderUTF8_Blended will be fine in some apps, but very slow in
others. It really depends on how you use it and how much text is being
rendered. You should cache the results of the rendering wherever possible.
In my projects, I’ve been dragging along a caching class that you’re
welcome to (no guarantees :).

Yes actually I had some code that regenerate the text surface only if menu
entry has changed or if the color has been updated (by time interval) and
that gone very messy and hard to maintain. That’s why I asked for a better
solution.

David.

Jonny D

On Tue, Feb 12, 2013 at 8:24 AM, David Demelier <demelier.david at gmail.com wrote:

Hello,

It is said on a lot of topics, web pages that generating texts with
SDL_ttf in blended mode is very slow. In my game, I would like to create a
menu with some font surfaces.

There is no problem using TTF_RenderUTF8_Blended. But I would like to
add a glowing effect, to show which menu entry is currently selected.

What I would like to do if possible, generating a text surface in any
colour you like and then apply some color or mask to alter the surface
colors, but I don’t know at all how to do that and if it’s possible.

So my questions are :

  1. Can I just call TTF_RenderUTF8_Blended in my main loop or it is very
    discouraged?
  2. If not how can I alter the surface color to get a blinking effect.

Cheers,


Demelier David


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Demelier David


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org