static void g_render() { static char sbuf[256]; // SDL_FillRect(front, &game[0].cords, SDL_MapRGB(front->format, 255, 255, 255)); // SDL_FillRect(front, &game[1].cords, SDL_MapRGB(front->format, 255, 0, 0)); SDL_BlitSurface( gbg, 0, front, 0); { SDL_Rect rc = { 20, 50, 640/2-40, 480-50 }; SDL_Rect rc2 = { 640/2+20, 50, 640/2-40, 480-50 }; SDL_FillRect(front, &rc, 0x0); SDL_FillRect(front, &rc2, 0x0); render_grid(&game[0], rc.x+5, rc.y+3); render_grid(&game[1], rc2.x+5, rc2.y+3); sprintf(sbuf, "P1 Score: %d Lines: %d", game[0].score, game[0].lines); SDL_PrintText(front, font, 25, 65, SDL_MapRGB(front->format, 255, 0, 0), sbuf); sprintf(sbuf, "P2 Score: %d Lines: %d", game[1].score, game[1].lines); SDL_PrintText(front, font, 640/2+25, 65, SDL_MapRGB(front->format, 255, 255, 255), sbuf); } game_logic(); }
int main(int argc, char **argv) { char *fn; int begin=0; int end=255; int size=10; int cpl=0; int cell=0; char autohinter=0; char seq=0; char alpha=0; char pack=0; FT_Library freetype; FT_Face face; int err; int i; char *out_fn="font.png"; char *def_fn=NULL; Font font; if(argc<2) { usage(); return 1; } while((i=getopt(argc, argv, "r:s:l:c:o:atvh?ed:p"))!=-1) { char *ptr; int temp; switch(i) { case 'r': if(!strcmp(optarg, "all")) { begin=0; end=0x110000; } else { if(!isdigit(optarg[0])) temp=-1; else { temp=strtol(optarg, &ptr, 0); if(ptr[0]!=',' || !isdigit(ptr[1])) temp=-1; } if(temp<0) { printf("Not a valid range: %s\n", optarg); exit(1); } else { begin=temp; end=strtol(ptr+1, NULL, 0); } } break; case 's': size=strtol(optarg, NULL, 0); break; case 'l': cpl=strtol(optarg, NULL, 0); break; case 'c': cell=strtol(optarg, NULL, 0); break; case 'o': out_fn=optarg; break; case 'a': autohinter=1; break; case 't': alpha=1; break; case 'v': ++verbose; break; case 'h': case '?': usage(); return 0; case 'e': seq=1; break; case 'd': def_fn=optarg; break; case 'p': pack=1; break; } } if(!strcmp(out_fn, "-")) verbose=0; if(optind!=argc-1) { usage(); return 1; } fn=argv[optind]; err=FT_Init_FreeType(&freetype); if(err) { fprintf(stderr, "Couldn't initialize FreeType library\n"); return 1; } err=FT_New_Face(freetype, fn, 0, &face); if(err) { fprintf(stderr, "Couldn't load font file\n"); if(err==FT_Err_Unknown_File_Format) fprintf(stderr, "Unknown file format\n"); return 1; } if(verbose) { const char *name=FT_Get_Postscript_Name(face); printf("Font name: %s\n", name); printf("Glyphs: %ld\n", face->num_glyphs); } err=FT_Set_Pixel_Sizes(face, 0, size); if(err) { fprintf(stderr, "Couldn't set size\n"); return 1; } font.size=size; init_font(&font, face, begin, end, autohinter); if(pack) render_packed(&font); else render_grid(&font, cell, cpl, seq); save_png(out_fn, &font.image, alpha); if(def_fn) save_defs(def_fn, &font); for(i=0; i<font.n_glyphs; ++i) free(font.glyphs[i].image.data); free(font.glyphs); free(font.image.data); FT_Done_Face(face); FT_Done_FreeType(freetype); return 0; }