SDL_ttf Problem with Bold [resolved]

Started by
4 comments, last by Peregrin 18 years, 7 months ago
I'm adding text to my GUI now, just on the forms in the title bar, and right now I'm going for that Windows look, so I checked to see what Windows uses. It's Tahoma, Bold, Size X. So, I added that in, but as soon as I make it bold, I get some breakup of my font as seen in this screenshot. Free Image Hosting at www.ImageShack.us As you can see the font is no longer solid. Now I know this issue came up a long time ago, but I can't find the thread for the life of me, and I just can't remember what has to be done to fix that issue. Does anyone know or have any ideas? Code segment for reference:

SDL_Color color = { 255, 255, 255 };
SDL_Surface *text_surface, *temp;
TTF_SetFontStyle( font, TTF_STYLE_BOLD );
if( text_surface = TTF_RenderText_Solid( font, "Hello World!", color ) ) 
{
	destRect.x = 23;
	destRect.y = 3;
	temp = SDL_DisplayFormat( text_surface );
	SDL_FreeSurface( text_surface );
	SDL_BlitSurface( temp, NULL, surface, &destRect );
}




[Edited by - Drew_Benton on September 14, 2005 11:39:11 PM]
Advertisement
Ok I got it solved. If anyone wants to know -

You will have to use the TTF_RenderText_Shaded function. If you are placing text over a background, like I was, then you will want to make the second color your colory key, and set transparency for that color so it's done correctly.

SDL_Color color = { 255, 255, 255 };SDL_Color color2 = { 0, 0, 0 };SDL_Surface *text_surface, *temp;TTF_SetFontStyle( font, TTF_STYLE_BOLD );if( text_surface = TTF_RenderText_Shaded( font, "Hello World!", color, color2 ) ) {	destRect.x = 23;	destRect.y = 3;	temp = SDL_DisplayFormat( text_surface );	SDL_FreeSurface( text_surface );        // Custom function that calls the set color key	SDL_SetTransparency( temp, 0, 0, 0);	SDL_BlitSurface( temp, NULL, surface, &destRect );}
Do you get nice results that way? It seems that if the background is not uniform, you should end up with jagged fonts. Try using TTF_RenderText_Blended for nice anti aliased glyphs.

Note that if you work with transparent surface, as your screen shot implies, blended fonts require some work. I have battled SDL for a long time to get font rendering working nicely in Jooleem. Basically, SDL can not properly blit one transparent surface onto another. I wrote a function that bypasses that by blending the pixels manually and stores the result in a new surface. It is expensive and relatively slow, but for one-off things like window titles it works fine.
Oops, sorry for the Anonymous Post.
Jooleem. Get addicted.
Quote:Original post by Anonymous Poster
Do you get nice results that way? It seems that if the background is not uniform, you should end up with jagged fonts. Try using TTF_RenderText_Blended for nice anti aliased glyphs.


Oh wow, thanks for that! Actualy I tried to use that function, but got nasty results that I just didn't use it again (as you will see in the screenshots below). However, something just came to mind and I realized I was using the wrong SDL_DisplayFormat function, I needed ot use the SDL_DisplayFormatAlpha instead, so now that works perfect, awesome!

Quote:Note that if you work with transparent surface, as your screen shot implies, blended fonts require some work. I have battled SDL for a long time to get font rendering working nicely in Jooleem. Basically, SDL can not properly blit one transparent surface onto another. I wrote a function that bypasses that by blending the pixels manually and stores the result in a new surface. It is expensive and relatively slow, but for one-off things like window titles it works fine.


Well right now, those surfaces aren't transparent in the sense of having a color key. I just used the SDL_SetAlpha function for that effect, and I think it's coming out great, have a look at these screenshots.

Using TTF_RenderText_Shaded (I see the artifacts on the grey title)
Free Image Hosting at www.ImageShack.us

Me being dumb (was using wrong function all along)
Free Image Hosting at www.ImageShack.us

Now this is how it's supposed to look [smile]
Free Image Hosting at www.ImageShack.us

I just now realized I should make the inactive text the right color as Windows does it, so here's the final screen shot of how it all looks
Free Image Hosting at www.ImageShack.us

Thanks again for that Peregrin! [smile] Oh and here's one last one of with no alpha being set.

Free Image Hosting at www.ImageShack.us

Thanks ImageShack lol [wink]
It looks very nice. Blended fonts are sexy. :)
Jooleem. Get addicted.

This topic is closed to new replies.

Advertisement