[SDL] SDL_ttf question

David Olofson david at olofson.net
Mon Jan 17 01:52:24 PST 2005

On Monday 17 January 2005 09.52, Kostas Kostiadis wrote:
> I'm using both SDL and OpenGL.
> Basicaly, I'm doing all the init stuff and handling input, events,
> timers, etc. via
> SDL, and I'm using openGL for rendering...
> I've based my font code to the glfont.c example that comes with
> the SDL_ttf sources.  Is there a more efficient way than the one
> described there?

More efficient in what way?

If you need lots of text at the same time as other stuff is going on, 
you probably need to render into temporary textures.

For a static overlay, just render it all into an RGBA texture of 
sufficient size. (Remember that some cards may not support 2048x2048 
or even 1024x1024 textures! You may have to do some tiling, or just 
hardwire your code for 256x256 tiles if that's easier.)

For scrolling, handle lines as separate textures and/or quads, or 
whatever suits your needs. The smaller the "tiles", the less texture 
memory you need for off-screen "scroll margin" - but of course, 
there's slightly more overhead.

If you need animated glyphs and stuff (assuming you don't have to 
animate *all* of them), you can just leave the animated glyphs out 
when rendering the static overlay textures, and render them "live" 

Of course, if to animate all glyphs in unison, you can just render one 
overlay texture for each frame, and "page flip" by switching texture 
every N ms or something. Or use color OpenGL modulation and/or 
transformations instead; they're pretty much free once you're in 
there rendering anyway...

I've been meaning to evolve the smoothscroll example into something 
more flexible and usable; a generic OpenGL sub-pixel smoothscrolling 
engine... (You supply a callback that renders the requested area of 
your map into an SDL surface, and the "engine" does the rest, pretty 
much.) That would be usable for scrolling text and overlaying 2D 
graphics on top of 3D or other "native" OpenGL stuff as well, I 
guess. However, that doesn't help much unless I actually get around 
to hack it. :-/

//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
|  Free/Open Source audio engine for games and multimedia.  |
| MIDI, modular synthesis, real time effects, scripting,... |
`-----------------------------------> http://audiality.org -'
   --- http://olofson.net --- http://www.reologica.se ---

More information about the SDL mailing list