#include #include #include TTF_Font* fontTTF = NULL; int getMaxHeight() { if (fontTTF != NULL) return TTF_FontHeight(fontTTF); else return 0; } void createAsciiImage(const std::string& fileName, unsigned int size) { if (fontTTF == NULL) return; int height = getMaxHeight(); // SDL_Color tmpColor = {0, 0, 0}; // Surface definition. SDL_Rect tmpRect; // this represents a Rectangle for blitting. SDL_Surface* tmpSurf = SDL_CreateRGBSurface(SDL_SWSURFACE, height*16, height*16, 32, #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */ 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 #else 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF #endif ); tmpRect.x = 0; tmpRect.y = 0; tmpRect.w = tmpSurf->w; tmpRect.h = tmpSurf->h; SDL_SetClipRect(tmpSurf, &tmpRect); int maxLineHeight = 0; int posX, posY; // all the interessting Glyphs for (posY = 0; posY < 16; posY++) { for (posX = 0; posX < 16; posX++) { SDL_Surface* glyphSurf = NULL; if (fontTTF != NULL) { SDL_Color white = {255, 255, 255}; glyphSurf = TTF_RenderGlyph_Blended(fontTTF, posX+16*posY, white); } if( glyphSurf != NULL ) { tmpRect.x = height*posX; tmpRect.y = height*posY; SDL_SetAlpha(glyphSurf, 0, 0); SDL_BlitSurface(glyphSurf, NULL, tmpSurf, &tmpRect); SDL_FreeSurface(glyphSurf); } } } SDL_SaveBMP(tmpSurf, fileName.c_str()); SDL_FreeSurface(tmpSurf); } int main (int argc, const char** argv) { SDL_Init(0); TTF_Init(); unsigned int renderSize = 32; fontTTF = TTF_OpenFont(argv[1], renderSize); createAsciiImage(argv[2], renderSize); // delete fontTTF; TTF_Quit(); SDL_Quit(); }