Game Development Reference
In-Depth Information
To use fonts within OpenGL, they need to be converted into a series of
OpenGL lists. OpenGL can use a series of commands in a single call by
storing them inside a list. The principle behind using fonts is to create a list
that describes to OpenGL how to draw each character within a font.
Thankfully we can use the Windows-specific function wglUseFontOut-
lines . Before we do this, we need to set the font we are intending to use
as the active font for the OpenGL window. We can easily display a font
selector using a font dialog box. The choice is stored as a LOGFONT
structure. The code used in Toon3D to display the font dialog box is as
follows:
void CGLTextDlg::OnTextSetfont()
{
CFontDialog dlg;
//Initialise the LOGFONT structure
dlg.m_cf.lpLogFont = &m_logfont;
//Tell the dialog box to use the LOGFONT member
dlg.m_cf.Flags |= CF_INITTOLOGFONTSTRUCT|CF_EFFECTS;
//Set the current colour
dlg.m_cf.rgbColors = m_clr;
//Display the dialog box
if (dlg.DoModal()==IDCANCEL) return;
//Store the new LOGFONT definition
dlg.GetCurrentFont(&m_logfont);
//Delete the old font
if (m_font.m_hObject) m_font.DeleteObject();
//Set the new one
m_fontready = m_font.CreateFontIndirect(&m_logfont);
//Update the colour value
m_clr = dlg.GetColor();
//Tell our dialog box to redraw itself
Invalidate(FALSE);
}
Using the MFC class CFontDialog involves initializing the member
variable m_cf, which is a CHOOSEFONT structure. When initializing this
member variable, we set the CF_INITTOLOGFONTSTRUCT and CF_
EFFECTS bits of the Flag member. CF_INITTOLOGFONTSTRUCT
informs the dialog box that the font is specified by the pointer to a logical
font, the lpLogFont member of the CHOOSEFONT structure. The CF_
Search Nedrilad ::




Custom Search