You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

66 lines
1.5 KiB

  1. /*
  2. * makefont.c: create a font bitmap from a .ttf file.
  3. * $Id$
  4. *
  5. * Copyright: (c) 2004 Sam Hocevar <sam@zoy.org>
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the Do What The Fuck You Want To
  8. * Public License as published by Banlu Kemiyatorn. See
  9. * http://sam.zoy.org/projects/COPYING.WTFPL for more details.
  10. *
  11. * Build example:
  12. * gcc -Wall makefont.c -o makefont `sdl-config --cflags --libs` -lSDL_ttf
  13. *
  14. * Usage:
  15. * makefont <font.ttf> <size> <text> <output.bmp>
  16. */
  17. #include <stdlib.h>
  18. #include <stdio.h>
  19. #include "SDL.h"
  20. #include "SDL_ttf.h"
  21. int main(int argc, char *argv[])
  22. {
  23. SDL_Color bg = { 0xff, 0xff, 0xff, 0 };
  24. SDL_Color fg = { 0x00, 0x00, 0x00, 0 };
  25. SDL_Surface *text;
  26. TTF_Font *font;
  27. if(argc != 5)
  28. {
  29. fprintf(stderr, "usage: %s <font.ttf> <size> <text> <output.bmp>\n",
  30. argv[0]);
  31. return 1;
  32. }
  33. TTF_Init();
  34. font = TTF_OpenFont(argv[1], atoi(argv[2]));
  35. if(!font)
  36. {
  37. fprintf(stderr, "could not load font %s: %s\n",
  38. argv[1], SDL_GetError());
  39. TTF_Quit();
  40. return 1;
  41. }
  42. TTF_SetFontStyle(font, TTF_STYLE_NORMAL);
  43. text = TTF_RenderUTF8_Shaded(font, argv[3], fg, bg);
  44. if(!text)
  45. {
  46. fprintf(stderr, "text rendering failed: %s\n", SDL_GetError());
  47. TTF_CloseFont(font);
  48. TTF_Quit();
  49. return 1;
  50. }
  51. SDL_SaveBMP(text, argv[4]);
  52. SDL_FreeSurface(text);
  53. TTF_CloseFont(font);
  54. TTF_Quit();
  55. return 0;
  56. }