[SDL] SDL_ttf question

David Olofson david at olofson.net
Mon Jan 17 02:54:14 PST 2005


On Monday 17 January 2005 11.14, Kostas Kostiadis wrote:
> more efficient in terms of cpu/gpu usage...
> At the moment what I'm doing everytime I want to render text is:
>
> create an SDL_Surface (via TTF_Render*_*)
> create a texture from the surface (using SDL_CreateRGBSurface,
> SDL_BlitSurface, etc.)
> enter 2D mode (glOrtho, push attribs, etc.)
> render the texture
> exit 2D mode
> Free the SDL_Surface

Surface creation/destruction should be outside the loop, so you only 
deal with textures and OpenGL, except when the text actually changes.

That is:

 render new text:
  * Free old SDL_Surface, if any
  * create an SDL_Surface (via TTF_Render*_*)
  * create a texture from the surface (using
    SDL_CreateRGBSurface,> SDL_BlitSurface, etc.)

 every frame:
  * enter 2D mode (glOrtho, push attribs, etc.)
  * render the texture
  * exit 2D mode

 cleanup:
  * Free the SDL_Surface


> The only thing I can think of to improve performance is batch all
> my render text calls and do them once a tick (so that all the
> enter/exit 2D mode, etc.
> happen only once).

The big hit is from rendering and convertion. The OpenGL stuff isn't 
nearly as expensive, in the normal case, I think.


> Also, am not sure how expensive SDL_BlitSurface is (from what I saw
> in the code
> it calls SDL_UpperBlit).

Depends on your CPU/GPU performance ratio (SDL blitting is 100% 
software when using SDL with OpenGL), but my guess is that your 
average video card blits many times faster than the CPU it's paired 
with - which would make SDL_BlitSurface() relatively expensive. And 
alpha blending (for antialiazing) slows down the CPU a lot, but 
doesn't bother a CPU much at all...


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