[SDL] Texture mapping fonts using SDL_tff
Ryan C. Gordon
icculus at icculus.org
Wed Feb 14 14:22:15 PST 2007
> // Copy pixel data from the SDL surface into the texture
> glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surface->w, surface->h, 0, GL_BGRA, GL_UNSIGNED_BYTE, surface->pixels);
Naturally, this only works if surface->w and surface->h are powers of
two (or you have the GL_ARB_texture_non_power_of_two extension)...this
can be difficult to promise when SDL_ttf hands back an arbitrary glyph's
bitmap, so you'll probably need to manually scale it or pad it with
empty pixels before uploading it to a texture.
Specifically for text, you might be able to put FTGL to work for you
better, though...it'll take a .ttf file, like SDL_ttf, but it can render
it via OpenGL primitives, so it will scale cleanly and probably take
less resources than building a surface, then building a texture. It can
use GL display lists or just immediate mode, so it should work on
anything that can legitimately call itself OpenGL.
It uses FreeType like SDL_ttf, so you really are just replacing the
SDL_ttf dependency with something else.
http://homepages.paradise.net.nz/henryj/code/#FTGL
Although I've used it with OpenGL too, SDL_ttf is really meant for 2D
display.
--ryan.
More information about the SDL
mailing list