Original Post
I am attempting to use multiple fonts in a program, but from what I can tell, it will only use the last font that I tried building. Here''s my font class.
From what I can tell, I am guessing that when a font is ''selected'' as per within the Build() function, it will only use that font. I ask because I am working on a project where having a clean thin font and a bold ''status'' font would be advantageous.
Thanks in advance.
Oh, and feel free to rip off this class. It seems to work well. Replace aString with your favorite string class.
class GLFont
{
public:
GLFont(){}
~GLFont()
{
glDeleteLists(base,256);
}
void Build(HDC hdc,const char* typeface,int height,int weight,bool italic = false,bool underline = false,bool strikethrough = false)
{
int charset;
m_hdc = hdc;
glDeleteLists(base,256);
base = glGenLists(256);
if (stricmp(typeface,"symbol") == 0)
charset = SYMBOL_CHARSET;
else
charset = ANSI_CHARSET;
fontid = CreateFont(height,0,0,0,weight,italic,underline,strikethrough,charset,OUT_TT_PRECIS,CLIP_DEFAULT_PRECIS,DRAFT_QUALITY,DEFAULT_PITCH,typeface);
SelectObject(hdc,fontid);
wglUseFontBitmaps(hdc,0,256,base);
GetCharWidth(hdc,0,255,widths);
this->height = height;
}
int Measure(aString str)
{
uint len = 0;
for (uint i = 0;i < strlen(str);i++)
{
len += widths[str[i]];
}
}
void Draw(aString str)
{
glPushAttrib(GL_LIST_BIT);
glListBase(base);
glCallLists((GLsizei)strlen(str),GL_UNSIGNED_BYTE,str);
glPopAttrib();
}
private:
HDC m_hdc;
HFONT fontid;
GLuint base;
int widths[256];
int height;
};