32 int ascii = 0, xOffset = 0, yOffset = 0, page = 0, first = 0, second = 0, kerning = 0;
34 char* charLinePattern =
35 "char id=%d%[ ]x=%d%[ ]y=%d%[ ]width=%d%[ ]height=%d%[ ]xoffset=%d%[ ]yoffset=%d%[ "
36 "]xadvance=%d%[ ]page=%d%[ ]\n";
40 ifs.open(filename.c_str(), std::ios::in | std::ios::binary);
47 std::getline(ifs, line);
48 std::getline(ifs, line);
49 std::getline(ifs, line);
50 std::getline(ifs, line);
53 std::getline(ifs, line);
54 if (sscanf_s(line.c_str(), charLinePattern, &ascii, spaces, (
unsigned)_countof(spaces), &
_invalid_char.
x,
55 spaces, (
unsigned)_countof(spaces), &
_invalid_char.
y, spaces, (
unsigned)_countof(spaces),
57 (
unsigned)_countof(spaces), &xOffset, spaces, (
unsigned)_countof(spaces), &yOffset, spaces,
59 &page, spaces, (
unsigned)_countof(spaces)) != 18)
66 while (std::getline(ifs, line))
71 if (sscanf_s(line.c_str(), charLinePattern, &ascii, spaces, (
unsigned)_countof(spaces), &
c.x, spaces,
72 (
unsigned)_countof(spaces), &
c.y, spaces, (
unsigned)_countof(spaces), &
c.w, spaces,
73 (
unsigned)_countof(spaces), &
c.h, spaces, (
unsigned)_countof(spaces), &xOffset, spaces,
74 (
unsigned)_countof(spaces), &yOffset, spaces, (
unsigned)_countof(spaces), &
c.advance,
75 spaces, (
unsigned)_countof(spaces), &page, spaces, (
unsigned)_countof(spaces)) == 18)
79 if (sscanf_s(line.c_str(),
"kerning first=%d%[ ]second=%d%[ ]amount=%d%[ ]", &first, spaces,
80 (
unsigned)_countof(spaces), &second, spaces, (
unsigned)_countof(spaces), &kerning,
81 spaces, (
unsigned)_countof(spaces)))
87 std::string tgaFilename = filename.substr(0, filename.find_last_of(
'.')) +
".tga";
88 ifs.open(tgaFilename.c_str(), std::ios::in | std::ios::binary);
95 ifs.seekg(12, std::ios::beg);
98 ifs.read((
char*)&
_sizeX, 2);
99 ifs.read((
char*)&
_sizeY, 2);
102 ifs.seekg(2, std::ios::cur);
106 _data =
new unsigned char[textureSize];
107 ifs.read((
char*)
_data, textureSize);
117 if (
c >= 0 &&
c < 256)
125 if (first >= 0 && first < 256 && second >= 0 && second < 256)
OGLFontChar _invalid_char
const int getKerning(unsigned char first, unsigned char second) const
std::vector< OGLFontChar > _char
virtual bool load(const std::string &filename)
const OGLFontChar & getChar(unsigned char c) const