Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre/Tools/BitmapFontBuilderTool/main.cpp @ 48

Last change on this file since 48 was 6, checked in by anonymous, 17 years ago

=…

File size: 3.1 KB
Line 
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>
12using namespace std;
13
14int main(int argc, char** argv)
15{
16    int size;
17    std::string datName, newName, fontName, imageName, genGlyph;
18    int addLeftPixels, addRightPixels;
19
20                cout << "Enter unique font name: ";
21                cin >> fontName;
22                cout << "Enter font image name: ";
23                cin >> imageName;
24                cout << "Enter size of texture(Example: 256): ";
25    cin >> size;
26    cout << "Enter name of file containing binary widths: ";
27    cin >> datName;
28
29    cout << endl;
30    cout << "If you've modified the output from BitmapFontBuilder, e.g. by adding a\n"
31            "dropshadow, you'll need to widen the glyphs a little. If you used\n"
32            "BitmapFontBuilder's output directly, just answer 0 in the following two\n"
33            "questions.\n";
34    cout << "Enter number of pixels to add to the left of all glyphs: ";
35    cin >> addLeftPixels;
36    cout << "Enter number of pixels to add to the right of all glyphs: ";
37    cin >> addRightPixels;
38    cout << endl;
39
40                cout << "Generate all glyph statements(Not Recommended)(Y/N): ";
41                cin >> genGlyph;
42    cout << "Enter name of new text file to create: ";
43    cin >> newName;
44
45    int charSize = size / 16;
46    int halfWidth = charSize / 2;
47    FILE *fp = fopen(datName.c_str(), "rb");
48
49    ofstream o(newName.c_str());
50
51                o << fontName << endl;
52                o << "{" << "\n\n";
53                o << "\ttype\timage" << endl;
54                o << "\tsource\t" << imageName << "\n\n\n";
55
56    int posx = 0;
57    int posy = 0; 
58    int colcount = 0;
59    for (int c = 0; c < 256; c++, colcount++)
60    {
61        if (colcount == 16)
62        {
63            colcount = 0;
64            posx = 0;
65            posy += charSize;
66        }
67
68        // Read width from binary file
69        int w1 = fgetc(fp) & 0xFF;      // NOTE: These two fgetc() have to be in seperate statements to ensure ordering!
70        int w2 = fgetc(fp) & 0xFF;
71        int width = w1 + (w2 << 8);     // Little endian only, but this tool isn't available for OSX anyway
72
73        float thisx_start = posx + halfWidth - (width / 2) - addLeftPixels;
74        float thisx_end = posx + halfWidth + (width / 2) + addRightPixels;
75
76        float u1, u2, v1, v2;
77        u1 = thisx_start / (float)(size) ;
78        u2 = thisx_end / (float)(size);
79        v1 = (float)posy / (float)(size);
80        v2 = (float)(posy + charSize) / (float)(size);
81
82                                if((genGlyph.at(0) == 'N' || genGlyph.at(0) == 'n') && c >= '!' && c <= '~')
83                                {
84                                        std::string s = " ";
85                                        s.at(0) = c;
86                                        o << "\tglyph " << s << " " << u1 << " " << v1 << " " << u2 << " " << v2 << std::endl;
87                                }
88                               
89                                if((genGlyph.at(0) != 'N' && genGlyph.at(0) != 'n'))
90                                {
91                                        std::string s = " ";
92                                        s.at(0) = c;
93                                        o << "\tglyph " << s << " " << u1 << " " << v1 << " " << u2 << " " << v2 << std::endl;
94                                }
95                                posx += charSize;
96
97    }
98                o << endl;
99                o << "}" << endl;
100    fclose(fp);
101
102    return 0;
103}
Note: See TracBrowser for help on using the repository browser.