Hi guys. I've been working on a class to handle fonts in open gl based on NeHe's tutorial 13 (Bitmap Fonts). It compiles fine, but doesn't display the text on screen. Heres the class code:
class CFont
{
public:
void put(const char *fmt, ...);
void DestroyFont();
void SetFont(HDC& thehdc, char* typeface, int height, int weight, bool italic, bool underlined, bool striked);
CFont();
~CFont();
private:
HFONT oldfont;
HFONT font;
int base;
};
CFont::~CFont()
{
DestroyFont();
}
void CFont::SetFont(HDC& thehdc, char* typeface, int height, int weight, bool italic, bool underlined, bool striked)
{
base = glGenLists(96); // Storage For 96 Characters
font = CreateFont( height, // Height Of Font
0, // Width Of Font
0, // Angle Of Escapement
0, // Orientation Angle
weight, // Font Weight
italic, // Italic
underlined, // Underline
striked, // 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
typeface); // Font Name
oldfont = (HFONT)SelectObject(thehdc, font); // Selects The Font We Want
wglUseFontBitmaps(thehdc, 32, 96, base); // Builds 96 Characters Starting At Character 32
SelectObject(thehdc, oldfont); // Selects The Font We Want
DeleteObject(font); // Delete The
}
void CFont::DestroyFont()
{
glDeleteLists(base, 96); // Delete All 96 Characters
}
void CFont:: Put(const char *fmt, ...)
{
char text[256]; // Holds Our String
va_list ap; // Pointer To List Of Arguments
if (fmt == NULL) // If There's No Text
return; // Do Nothing
va_start(ap, fmt); // Parses The String For Variables
vsprintf(text, fmt, ap); // And Converts Symbols To Actual Numbers
va_end(ap); // Results Are Stored In Text
glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits
glListBase(base - 32); // Sets The Base Character to 32
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // Draws The Display List Text
glPopAttrib(); // Pops The Display List Bits
}
As you can see its nearly the same as in the turtorial, just in a class so its contained. In my twisted world, I'm thinking I can change the font by calling DestroyFont(), then SetFont() again with new font settings. At the moment SetFont() takes a reference to the DC, is that where its going wrong? It compiles with no errors or warnings, and idears? Just in case I'll leave my drawing test code here:
int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The Current Modelview Matrix
glTranslatef(0.0,0.0,-1.0);
glRasterPos2f(0.0,0.0);
glColor3f(1.0,1.0,1.0);
font.put("Hello World!");
return TRUE; // Everything Went OK
}
Thx,
-J
PS: how do u make those wite scroll boxes of code again?
[edited by - jason2jason on May 6, 2002 8:45:02 AM]
[edited by - jason2jason on May 6, 2002 6:06:21 PM]