int main(int argc, char **argv) { int i; glutInit(&argc, argv); for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-sb")) { doubleBuffer = 0; } else if (!strcmp(argv[i], "-v")) { verbose = 1; } else { filename = argv[i]; } } if (filename == NULL) { fprintf(stderr, "usage: showtxf [GLUT-options] [-sb] [-v] txf-file\n"); exit(1); } txf = txfLoadFont(filename); if (txf == NULL) { fprintf(stderr, "Problem loading %s\n", filename); exit(1); } imgwidth = txf->tex_width; imgheight = txf->tex_height; printf("---w:%d h: %d num_g:%d max_a:%d max_d:%d\n",imgwidth,imgheight, txf->num_glyphs, txf->max_ascent, txf->max_descent); /*inverse colors*/ {int i,j; for(i=0;i<imgwidth;i++) for(j=0;j<imgheight;j++){ txf->teximage[i + j * imgwidth] ^= 255; } } /**/ if (doubleBuffer) { glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); } else { glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE); } glutInitWindowSize(imgwidth, imgheight); glutCreateWindow(filename); glutReshapeFunc(reshape); glutDisplayFunc(display); glutMouseFunc(mouse); glutMotionFunc(motion); /* Use a gray background so teximage with black backgrounds will show against showtxf's background. */ glClearColor(0.2, 0.2, 0.2, 1.0); glutMainLoop(); return 0; /* ANSI C requires main to return int. */ }
CacheRef< CachedFont > get_font(string name) { string key = "font:" + name; CacheRef< CachedFont > ret(NULL); CachedFont *item = (CachedFont *)get_cache().get_item(key); if (!item) { TexFont *font = txfLoadFont(name.c_str()); if (font == NULL) { cerr << "Error loading font '" << name << "'." << endl; return ret; } item = new CachedFont(font); get_cache().add_item(key, item); } if (item->id != FONT_ID) { cerr << "Item with key '" << key << "' isn't a font." << endl; return ret; } ret.set(item); return ret; }