Request for Comments

I’m looking into some demos and stuff for SDL.
It strikes me that there is no way of easily displaying text in SDL.

How about this in a library in the “examples” directory?

This is a wrapper around the FreeType 1.0 engine, allowing SDL applications
to easily put text on the display, using a .ttf format TrueType font file.

API:
int TTF_Init(void);
int TTF_OpenFont(char *file, int ptsize, TTF_font *font);
int TTF_RenderTo(TTF_font *font, char *text, Uint32 color,
SDL_Surface *display, SDL_Rect *offset);
SDL_Surface *TTF_RenderText(TTF_font *font, char *text, Uint32 color);
void TTF_CloseFont(TTF_font *font);
int TTF_Quit(void);

The code hasn’t been written yet, but the API would look something like that.

Comments?

See ya!
-Sam Lantinga (slouken at devolution.com)–
Author of Simple DirectMedia Layer -
http://www.devolution.com/~slouken/SDL/

How about this in a library in the “examples” directory?

Why not just make it part of the std. distribution? SDL_text?

Also, It’d be nice to support fonts consisting of just a bitmap file with
all the chars contained in it for doing custom title scrollers etc. That
would be cool if you could test the demo/app with true type, then when
you’ve got 4 hours to spare, just knock up a pretty font.

The Api is cool, but I’d remove the TTs if you are going to include
support for Bitmapped fonts.

njh
p.s. I’ve started work on SDL_sound3dOn Sat, 18 Apr 1998, Sam Lantinga wrote:

Why not just make it part of the std. distribution? SDL_text?

I don’t want to add anything that relies on external programs or libraries
to the official SDL distribution.

Also, It’d be nice to support fonts consisting of just a bitmap file with
all the chars contained in it for doing custom title scrollers etc. That
would be cool if you could test the demo/app with true type, then when
you’ve got 4 hours to spare, just knock up a pretty font.

That’s easy (Assuming a bitmap of the capital letters, monospaced):

SDL_Surface *rawfont, *font;
SDL_Rect fontsrc, dst;
char letter;  /* in the range 'A' - 'Z' */

rawfont = SDL_LoadBMP("font.bmp");

...
font = SDL_DisplayFormat(rawfont);

...
fontsrc.x = (letter-'A')*glyphwidth;
fontsrc.y = 0;
fontsrc.w = glyphwidth;
fontsrc.h = font->h;
SDL_BlitSurface(font, &fontsrc, screen, &dst);

There’s no reason to add code to support various bitmap font formats.
That’s what example libs and game coders are for. :slight_smile:

p.s. I’ve started work on SDL_sound3d

Cool! :slight_smile:

See ya!
-Sam Lantinga (slouken at devolution.com)–
Author of Simple DirectMedia Layer -
http://www.devolution.com/~slouken/SDL/