Original Post
Hi. I''ve been doing a font class (again) based on NeHe''s tutorial on Bitmap Fonts. It looks fine (almost the same as NeHe''s code), it even compiles without any error or warning messages, but the font doesn''t display. CAn anyone see anything i can''t? Heres my code:
thx,
-J
class CFont
{
public:
void Write(float x, float y, char* text, ...);
void DestroyFont();
void CreateBMFont(HDC& hdc, char* FontName, int size, int weight, DWORD Italic, DWORD Underline, DWORD Strikeout);
CFont();
virtual ~CFont();
private:
UINT FontInd;
};
void CFont::CreateBMFont(HDC& hdc, char* FontName, int size, int weight, DWORD Italic, DWORD Underline, DWORD Strikeout)
{
HFONT hFont; //Font handle
HFONT hOldFont; //Apparently for good house keeping
FontInd = glGenLists(256); //Generate font lists
hFont = CreateFont( size, //Set up font
0,
0,
0,
weight,
Italic,
Underline,
Strikeout,
ANSI_CHARSET,
OUT_TT_PRECIS,
CLIP_DEFAULT_PRECIS,
ANTIALIASED_QUALITY,
FF_DONTCARE|DEFAULT_PITCH,
FontName
);
hOldFont = (HFONT)SelectObject(hdc, hFont); // Selects The Font We Want
wglUseFontBitmaps(hdc, 32, 96, FontInd); // Builds 96 Characters Starting At Character 32
SelectObject(hdc, hOldFont); // Selects The Font We Want
DeleteObject(hFont); // Delete The Font
}
void CFont::DestroyFont()
{
glDeleteLists(FontInd, 96); //Delete the 96 chars in the dis lists.
}
void CFont::Write(float x, float y, char* text, ...)
{
if(text == NULL) //If there''s no text then return
return;
va_list pargs; //Argument list pointer
char string[256]; //Final output string
glRasterPos2f(x,y); //Position text (in 2D) with users x,y coord''s
va_start(pargs, text); // Parses The String For Variables
vsprintf(string, text, pargs); // And Converts Symbols To Actual Numbers
va_end(pargs); // Results Are Stored In Text
glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits
glListBase(FontInd - 32); // Sets The Base Character to 32
glCallLists(strlen(string), GL_UNSIGNED_BYTE, string); // Draws The Display List Text
glPopAttrib(); // Pops The Display List Bits
}