Hey,
To put these onto a single surface, you should probably blit each line to a new surface. Try something like this:
int drawTTFSolid(TTF_Font font, const char text, SDL_Surface dest, SDL_Rect drect, SDL_Color fg)
{
int h;
SDL_Surface* textSurf = TTF_RenderText_Solid(font, text, fg);
SDL_BlitSurface(textSurf, NULL, dest, &drect);
h = textSurf->h;
SDL_FreeSurface(textSurf);
return h;
}
SDL_Surface* result = SDL_CreateRGBSurface(Fill this in…);SDL_Rect rect;
rect.x = 0;
rect.y = 0;
rect.y += drawTTFSolid(somefont, “abcdefghijklmnopqrstuvwxyz”, result, &rect, somecolor);
rect.y += drawTTFSolid(somefont, “ABCDEFGHIJKLMNOPQRSTUVWXYZ”, result, &rect, somecolor);
rect.y += drawTTFSolid(somefont, “0123456789”, result, &rect, somecolor);
rect.y += drawTTFSolid(somefont, “.!@#$%^&*”, result, &rect, somecolor);
// Now result should have all my text!
That should just about do it. Now, I haven’t ever used SDL_ttf, so I’m wary of those weird symbols in the last string.
-Jonny D
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’twant 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 ofCPU 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 2for each glyph and store each glyph separately. This has the disadvantage ofwasting 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 largetexture to store all the glyphs, and copy glyphs from it at draw time. Thispotentially 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 workedwell for me._______________________________________________ SDL mailing listSDL at lists.libsdl.orghttp://lists.libsdl.org/listinfo.cgi/sdl-libsdl.orgDate: Tue, 30 Oct 2007 20:53:36 -0400From: sean at code-box.orgTo: sdl at lists.libsdl.orgSubject: Re: [SDL] SDL_ttf and openglIlya,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: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.!@#$%^&*How will I get 4 lines of SDL_ttf data to a single surface like that?Thanks again!
On 10/30/07, Ilya Olevsky wrote:
Climb to the top of the charts!? Play Star Shuffle:? the word scramble challenge with star power.
http://club.live.com/star_shuffle.aspx?icid=starshuffle_wlmailtextlink_oct