Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SDL not rendering truetype font

I'm not entirely sure this is the best place for this, but I can't think of anywhere better

I've "made" a low resolution font. (bonus points if you know where it's actually from)

The font works fine in gedit: gedit

However, when trying to render the font with SDL_ttf, it mostly works, except for some multibyte unicode characters (notably 'æ' and '℃') while other non-ASCII characters work fine. But(!), all of these characters work fine with other fonts (I've been using DejaVu Sans)

My FontDejavu Sans

The fact that other fonts work fine suggest that the code is not to blame, but just in case:

SDL_Surface *surf = TTF_RenderUTF8_Solid(this->font, (const char *)text, col);
if (surf == nullptr) {
    fprintf(stderr, "Rendering text failed (%s)\n", TTF_GetError());
    return;
}

if (surf->format->BitsPerPixel != 8 || surf->format->BytesPerPixel != 1) {
    fprintf(stderr, "Rendering text failed (Wrong surface format)\n");
    return;
}

(text is const uint8*) None of these errors are triggered, obviously

I've noticed that these 2 characters in particular are wider than the rest, could this be to blame?

Per comment below, the font seems to work fine with the SDL_TTF "latin-1" demo:

working in demo

like image 793
LordAro Avatar asked Aug 03 '14 19:08

LordAro


1 Answers

I.. I don't know what was wrong. I just tried it again, and it worked fine.

enter image description here

I was so sure I'd checked that I was using the correct font.. Or maybe I changed something when I generated it

Thanks for the help regardless :)

like image 90
LordAro Avatar answered Nov 16 '22 03:11

LordAro