Bah… it didnt work. I think I should post my entire code here:
//—Header file-------//
struct rtFont
{
TCHAR fName[30];
TCHAR FaceName[30];
int size;
bool bold;
bool italic;
bool underline;
HFONT hf;
GLuint base;
};
class CRT2D
{
public:
…
…
private:
int nFonts;
vector<rtFont> font;
};
//----Source file----//
void CRT2D::CreateBitmapFont(LPCTSTR Name, LPCTSTR FontName, int size, bool bold, bool italic, bool underline)
{
nFonts++;
rtFont f;
font.push_back(f);
strcpy (font[nFonts-1].fName, Name);
strcpy (font[nFonts-1].FaceName,FontName);
font[nFonts-1].bold=bold;
font[nFonts-1].underline=underline;
font[nFonts-1].italic=italic;
font[nFonts-1].size=size;
font[nFonts-1].base = glGenLists(96);
font[nFonts-1].hf = CreateFont(-size,0,0,0,bold?FW_BOLD:FW_NORMAL,italic?TRUE:FALSE,underline?TRUE:FALSE,FALSE,ANSI_CHARSET,OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,ANTIALIASED_QUALITY,FF_DONTCARE|DEFAULT_PITCH,FontName);
wglUseFontBitmaps(hdc,32,96,font[nFonts-1].base);
}
void CRT2D::RenderText(LPCTSTR Name, LPCTSTR Text, Vec2 pos, RGBA color)
{
if (text==NULL)
return;
int h = Fonts(Name);
if (h<0) return;
char t[256];
glColor4f(color);
//font to use
SelectObject(hdc, font[h].hf);
glRasterPos2f(pos.x,pos.y);
sprintf(t,"%s",text);
glPushAttrib(GL_LIST_BIT);
glListBase(font[h].base-32);
glCallLists(strlen(t),GL_UNSIGNED_BYTE,t);
glPopAttrib();
}
//the search routine
int CRT2D::Fonts(LPCTSTR name)
{
int nIndex=0;
vector<rtFont>::const_iterator ib=font.begin();
vector<rtFont>::const_iterator ie=font.end();
vector<rtFont>::const_iterator i;
for (i=ib; i!=ie; i++,nIndex++)
{
if (strcmp((*i).fName,name)==0)
return nIndex;
}
return -1;
}
Thats it. This rendering code shows nothing on the screen. If I place the wglUseFontBitmaps(…) inside the render loop, it works, but it is all messed up.
[This message has been edited by kaysoft (edited 10-10-2002).]