SDL_Font is a C++ addon for SDL
to allow you to display your windows and homebrewed fonts in SDL. Since SDL_ttf
requires a bunch of dependencys and I never could get any of it to work i wrote
my own. It includes C -style stream formated text and the ability to
stretch the font, and change its color Heres a example SDL program displaying a
Arial MXF font
The source code
is the following.
#include<SDL.h>
#include "SDL_font.h"
int main(int argc, char **argv) {
SDL_Surface *front;
SDL_Font font;
atexit(SDL_Quit);
if(SDL_Init(SDL_INIT_VIDEO) < 0) {
std::cerr << "Error Initalizing SDL!\n";
return 0;
}
if(!(front = SDL_SetVideoMode(640,480,0,0))) {
std::cerr << "Error Setting Display Mode!\n";
return 0;
}
if(!(SDL_read_font(&font,"arial.mxf"))) {
std::cerr << " Error reading font arial.mxf ! \n";
return 0;
}
SDL_Event e;
bool active = true;
while(active == true) {
SDL_Rect rc = { 0,0,640,480 };
SDL_FillRect(front, &rc, 0x0);
SDL_PrintText(front, &font, 0,0,SDL_MapRGB(front->format, rand()%255, rand()%255, rand()%255), "This is a test of the font \n function!\n =)");
while(SDL_PollEvent(&e)) {
switch(e.type) {
case SDL_QUIT:
active = false;
break;
}
}
SDL_UpdateRect(front,0,0,640,480);
}
SDL_FreeSurface(front);
return 0;
}