[SDL] SDL_ttf and opengl

Martin Gerhardy martin.gerhardy at gmail.com
Wed Oct 31 03:13:58 PDT 2007


Am Dienstag, den 30.10.2007, 20:53 -0400 schrieb Sean Kerr:
> Ilya,
> 
> Thanks. This is great information and has solidified my original
> thought. Render to individual glyph and reuse them individually. I
> will most likely be generating only a-z, A-Z, 0-9 and possibly some
> punctuation characters. That shouldn't be too bad on the texture
> memory usage should it? 
> 
> Could you give me a few tips on how I might generate multiple lines of
> SDL_ttf words to a single surface in SDL? Is that possible, or am I
> stuck somehow generating to multiple surfaces first and joining them
> somehow, and then extracting the pixel data? I was thinking generating
> a surface like this and loading it into texture memory: 
> 
> abcdefghijklmnopqrstuvwxyz
> ABCDEFGHIJKLMNOPQRSTUVWXYZ
> 0123456789
> .!@#$%^&*

And what about i18n? Why are you using SDL_ttf at all and not bitmap
fonts or SDL_font?

> How will I get 4 lines of SDL_ttf data to a single surface like that?
> 
> Thanks again!
> 
> 
> On 10/30/07, Ilya Olevsky <info at valengames.com> wrote:
>         Sean Kerr wrote:
>         > I'm wondering if there's an easy way to use SDL_ttf for
>         rendering fonts to a
>         > surface, then using that surface in an opengl window. Would
>         it be smarter to
>         > generate glyphs one by one and store them as an opengl
>         texture, or would it 
>         > be smarter to generate (when i need it) a sentence at a time
>         and then map
>         > the surface pixels to a quad?
>         
>         Generate the glyphs and convert them to textures (or one
>         texture). You don't
>         want to convert between a surface and texture in real time. I
>         also don't think 
>         it's prudent to generate surfaces/textures for series of
>         letters (words,
>         sentences) because that simply wastes memory while saving only
>         a little bit of
>         CPU overhead of individual glyph based rendering.
>         
>         > Also, if the surface isn't a power of 2 I cannot use it in
>         opengl, so I'm
>         > wondering if you guys have any techniques for modifying that
>         ability a bit
>         > to make it easy to use SDL_ttf with opengl. 
>         
>         There are a couple of options. You can create a texture of
>         nearest power of 2
>         for each glyph and store each glyph separately. This has the
>         disadvantage of
>         wasting some of the texture space, but I don't know how big of
>         a deal that is 
>         (whether GL will compress it for you or not). You can also
>         create one large
>         texture to store all the glyphs, and copy glyphs from it at
>         draw time. This
>         potentially can be a problem if you use a very large texture
>         size. Although this 
>         may not be as much of a problem with modern video cards as it
>         used to be.
>         
>         Personally I generate a nearest power of 2 texture for each
>         glyph. It has worked
>         well for me.
>         
>         _______________________________________________ 
>         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



More information about the SDL mailing list