SDL_ttf : TTF_RenderUTF8_Blended giving garbled output

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
User avatar
wich
Posts: 13
Joined: Wed Feb 14, 2007 6:05 am

SDL_ttf : TTF_RenderUTF8_Blended giving garbled output

Post by wich »

Hi people, I'm using SDL with SDL_ttf to produce some text in my application, but it seems that something is going wrong and I haven't the slightest idea as to what could be going wrong. Below is the function I am currently using (surf here is the primary video surface):

Code: Select all

inline void drawtext(TTF_Font* font, char* string, size_t x, size_t y, SDL_Color color) {
  SDL_Surface* text = TTF_RenderUTF8_Blended(font, string, color);
  SDL_Surface* text_display_format = SDL_DisplayFormatAlpha(text);
  SDL_FreeSurface(text);
  SDL_Rect dest = {x, y, 0, 0};
  SDL_SetAlpha(text_display_format, SDL_SRCALPHA, SDL_ALPHA_TRANSPARENT);
  SDL_BlitSurface(text_display_format, 0, surf, &dest);
  SDL_FreeSurface(text_display_format);
}
All I get is some garbled glyphs, while when I use TTF_RenderUTF8_Solid everything works fine. I've been googling around the net, but I've not been able to find any useful material. Has anybody an idea as to what I'm doing wrong, or can point me in the right direction? I'd also appreciate it if someone could point me to another project that uses TTF_Render*_Blended on the PSP, so that I can compare what I'm doing to other code.
Post Reply