Changeset 446 for pwntcha/trunk/extras/makefont.c
- Timestamp:
- Jan 10, 2005, 2:21:50 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pwntcha/trunk/extras/makefont.c
r443 r446 18 18 #include <stdlib.h> 19 19 #include <stdio.h> 20 #include <string.h> 20 21 21 22 #include "SDL.h" … … 24 25 int main(int argc, char *argv[]) 25 26 { 27 unsigned char *text; 26 28 SDL_Color bg = { 0xff, 0xff, 0xff, 0 }; 27 29 SDL_Color fg = { 0x00, 0x00, 0x00, 0 }; 28 SDL_Surface * text;30 SDL_Surface *surface; 29 31 TTF_Font *font; 32 int i; 30 33 31 34 if(argc != 5) … … 36 39 } 37 40 41 /* Load font */ 38 42 TTF_Init(); 39 43 font = TTF_OpenFont(argv[1], atoi(argv[2])); … … 46 50 } 47 51 52 /* Add spaces to string */ 53 text = malloc(2 * strlen(argv[3]) * sizeof(char)); 54 for(i = 0; argv[3][i]; i++) 55 { 56 text[i * 2] = argv[3][i]; 57 text[i * 2 + 1] = ' '; 58 } 59 text[i * 2 - 1] = '\0'; 60 61 /* Render text to surface */ 48 62 TTF_SetFontStyle(font, TTF_STYLE_NORMAL); 49 text= TTF_RenderUTF8_Shaded(font, argv[3], fg, bg);50 if(! text)63 surface = TTF_RenderUTF8_Shaded(font, argv[3], fg, bg); 64 if(!surface) 51 65 { 52 fprintf(stderr, " textrendering failed: %s\n", SDL_GetError());66 fprintf(stderr, "surface rendering failed: %s\n", SDL_GetError()); 53 67 TTF_CloseFont(font); 54 68 TTF_Quit(); … … 56 70 } 57 71 58 SDL_SaveBMP(text, argv[4]); 59 SDL_FreeSurface(text); 72 /* Clean up surface */ 73 74 /* Save surface and free everything */ 75 SDL_SaveBMP(surface, argv[4]); 76 SDL_FreeSurface(surface); 60 77 TTF_CloseFont(font); 61 78 TTF_Quit();
Note: See TracChangeset
for help on using the changeset viewer.