int Font::load()
{
// the font definition is in the filename as provided:
// <name>:<size>[:options].font
HFONT oldFont;
HFONT newFont;
tagSIZE letterSize;
HDC hDC;
int size;
char* sizepos;
char* optpos;
unsigned char letter;
int opt_bold = FW_NORMAL;
int opt_italic = FALSE;
int opt_underline = FALSE;
int opt_strike = FALSE;
Data<HDC>* d = (Data<HDC>*)CDC::INSTANCE()->getData(DATA_TYPE_HDC);
if (d)
{
hDC = d->get();
}
else
{
return -1;
}
if ((sizepos = strchr(fileName,':')) == NULL)
{
return -1;
}
if ((optpos = strchr(&sizepos[1],':')) != NULL)
{
*optpos = '\0';
letter = optpos[1];
while (letter != '.' && letter != '\0')
{
if (letter == 'b' || letter == 'B')
{
opt_bold = FW_BOLD;
}
if (letter == 'i' || letter == 'I')
{
opt_italic = TRUE;
}
if (letter == 'u' || letter == 'U')
{
opt_underline = TRUE;
}
if (letter == 's' || letter == 'S')
{
opt_strike = TRUE;
}
letter = optpos[1];
optpos = &optpos[1];
}
}
else if ((optpos = strchr(fileName,'.')) != NULL)
{
*optpos = '\0';
}
if (sscanf(sizepos,":%i",&size) != 1)
{
return -1;
}
*sizepos = '\0'; // concat the string again. <name>:<size> becomes <name><NULL><size> effecively making it <name>
this->texture = glGenLists(256);
if (this->texture == -1 || this->texture == 0) // error occured while creating font
return -1;
newFont = CreateFont( -size, // Height Of Font ( NEW )
0, // Width Of Font
0, // Angle Of Escapement
0, // Orientation Angle
opt_bold, // Font Weight
opt_italic, // Italic
opt_underline, // Underline
opt_strike, // Strikeout
ANSI_CHARSET, // Character Set Identifier
OUT_TT_PRECIS, // Output Precision
CLIP_DEFAULT_PRECIS, // Clipping Precision
ANTIALIASED_QUALITY, // Output Quality
FF_DONTCARE|DEFAULT_PITCH, // Family And Pitch
fileName); // Font Name
oldFont = (HFONT)SelectObject(hDC, newFont); // Selects The Font We Want
wglUseFontBitmaps(hDC, 0, 256, this->texture); // Builds 256 Characters Starting At Character 0
for (letter=0; letter<255; letter++) // loop through all letters and extract their width and height
{
GetTextExtentPoint(hDC,(char*)&letter,1,&letterSize);
fontWidth[letter] = letterSize.cx;
fontHeight[letter] = letterSize.cy;
}
SelectObject(hDC, oldFont); // Selects The Font We Want
return 0;
}
glListBase(texture->texture);
glCallLists( strlen(t->getText()), GL_UNSIGNED_BYTE, t->getText());