[SDL] TTF_RenderText_Sold - Unevenly spaced characters.
Nick Jennings
nick at namodn.com
Sat Jan 5 14:10:01 PST 2002
Perhaps I did not explain myself clearly enough for my question to be
answered easily. Basically, the function 'displayText' will iterate
through the string one character at a time, checking for \n (in wich
case it changes the dest.* to a new line). If it's a character it
displays the character and uses the size of text->w to space dest.x
over enough for the next character.
The problem is, if I pass the string "test message" or something,
the output is unevenly spaced between characters.
t est m ess ag e
the real output is much more fine grained as the fonts are not fixed
as they are in this email. But you get the idea.
I need to figure out how to set dest.x to be in the correct position
for the next character to display, so the message comes out looking
perfectly even (as if the entire string had been displayed in one
call to 'TTF_RenderText_Solid'.
All help appreciated.
On Fri, Jan 04, 2002 at 05:23:44PM -0800, Nick Jennings wrote:
>
> int displayText(SDL_Surface *screen, TTF_Font *font, SDL_Color color,
> char *string) {
> static int iTop = 0;
> static SDL_Rect dest;
> SDL_Surface *text;
> int i = 0;
> char c[2] = {'\0'};
>
> if (!iTop) {
> iTop = 1;
> dest.x = 0;
> dest.y = 4;
> }
>
> while (*(string+i) != '\0') {
> switch (*(string+i)) {
> case '\n':
> dest.x = 0;
> dest.y = dest.y + 18;
> i++;
> break;
> default:
> c[0] = *(string+i);
> text = TTF_RenderText_Solid(font, c, color);
> if ( text == NULL ) {
> fprintf(stderr, "Unable to render text: %s\n", SDL_GetError());
> return(0);
> }
> printf("%s, %d\n", c, text->w);
> SDL_BlitSurface(text, NULL, screen, &dest);
> SDL_UpdateRect(screen, 0, 0, 0, 0);
>
> if ( SDL_SetColorKey(text, SDL_SRCCOLORKEY|SDL_RLEACCEL, 0) < 0 ) {
> fprintf(stderr, "Warning: Couldn't set text colorkey: %s\n",
> SDL_GetError());
> return(0);
> }
> dest.x = dest.x + text->w;
> SDL_FreeSurface(text);
> i++;
> break;
> }
> }
> return(1);
> }
>
> --
> Nick Jennings
>
>
> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl
>
--
Nick Jennings
More information about the SDL
mailing list