# SDL_ttf Problem with Bold [resolved]

This topic is 4872 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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. 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]

##### Share on other sites
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 );}

##### Share on other sites
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.

##### Share on other sites
Oops, sorry for the Anonymous Post.

##### Share on other sites
Quote:
 Original post by Anonymous PosterDo 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)

Me being dumb (was using wrong function all along)

Now this is how it's supposed to look [smile]

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

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

Thanks ImageShack lol [wink]

##### Share on other sites
It looks very nice. Blended fonts are sexy. :)

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 15
• 14
• 46
• 22
• 27
• ### Forum Statistics

• Total Topics
634047
• Total Posts
3015232
×