1 |
|
---|
2 | /** Tool designed to take the binary width files from BitmapFontBuilder
|
---|
3 | http://www.lmnopc.com/bitmapfontbuilder/ and convert them into
|
---|
4 | Ogre .fontdef 'glyph' statements.
|
---|
5 | Highly inelegant, but it works!
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include <iostream>
|
---|
9 | #include <fstream>
|
---|
10 | #include <string>
|
---|
11 | #include <math.h>
|
---|
12 | using namespace std;
|
---|
13 |
|
---|
14 | int main(int argc, char** argv)
|
---|
15 | {
|
---|
16 | int size;
|
---|
17 | std::string datName, newName, fontName, imageName, genGlyph;
|
---|
18 |
|
---|
19 | cout << "Enter unique font name: ";
|
---|
20 | cin >> fontName;
|
---|
21 | cout << "Enter font image name: ";
|
---|
22 | cin >> imageName;
|
---|
23 | cout << "Enter size of texture(Example: 256): ";
|
---|
24 | cin >> size;
|
---|
25 | cout << "Enter name of file containing binary widths: ";
|
---|
26 | cin >> datName;
|
---|
27 | cout << "Generate all glyph statements(Not Recommended)(Y/N): ";
|
---|
28 | cin >> genGlyph;
|
---|
29 | cout << "Enter name of new text file to create: ";
|
---|
30 | cin >> newName;
|
---|
31 |
|
---|
32 | int charSize = size / 16;
|
---|
33 | int halfWidth = charSize / 2;
|
---|
34 | FILE *fp = fopen(datName.c_str(), "rb");
|
---|
35 |
|
---|
36 | ofstream o(newName.c_str());
|
---|
37 |
|
---|
38 | o << fontName << endl;
|
---|
39 | o << "{" << "\n\n";
|
---|
40 | o << "\ttype\timage" << endl;
|
---|
41 | o << "\tsource\t" << imageName << "\n\n\n";
|
---|
42 |
|
---|
43 | int posx = 0;
|
---|
44 | int posy = 0;
|
---|
45 | int colcount = 0;
|
---|
46 | for (int c = 0; c < 256; c++, colcount++)
|
---|
47 | {
|
---|
48 | if (colcount == 16)
|
---|
49 | {
|
---|
50 | colcount = 0;
|
---|
51 | posx = 0;
|
---|
52 | posy += charSize;
|
---|
53 | }
|
---|
54 |
|
---|
55 | int width = fgetc(fp);
|
---|
56 | float thisx_start = posx + halfWidth - (width / 2);
|
---|
57 | float thisx_end = posx + halfWidth + (width / 2);
|
---|
58 |
|
---|
59 | float u1, u2, v1, v2;
|
---|
60 | u1 = thisx_start / (float)(size) ;
|
---|
61 | u2 = thisx_end / (float)(size);
|
---|
62 | v1 = (float)posy / (float)(size);
|
---|
63 | v2 = (float)(posy + charSize) / (float)(size);
|
---|
64 |
|
---|
65 | if((genGlyph.at(0) == 'N' || genGlyph.at(0) == 'n') && c >= '!' && c <= '~')
|
---|
66 | {
|
---|
67 | std::string s = " ";
|
---|
68 | s.at(0) = c;
|
---|
69 | o << "\tglyph " << s << " " << u1 << " " << v1 << " " << u2 << " " << v2 << std::endl;
|
---|
70 | }
|
---|
71 |
|
---|
72 | if((genGlyph.at(0) != 'N' && genGlyph.at(0) != 'n'))
|
---|
73 | {
|
---|
74 | std::string s = " ";
|
---|
75 | s.at(0) = c;
|
---|
76 | o << "\tglyph " << s << " " << u1 << " " << v1 << " " << u2 << " " << v2 << std::endl;
|
---|
77 | }
|
---|
78 | posx += charSize;
|
---|
79 |
|
---|
80 | }
|
---|
81 | o << endl;
|
---|
82 | o << "}" << endl;
|
---|
83 | fclose(fp);
|
---|
84 |
|
---|
85 | return 0;
|
---|
86 | }
|
---|