I have decided to try drawing text using wglUseFontBitmaps() (in openGL). I have multple windows, and I want to be able to draw on them with the same font. The implementation I have so far is this :
Code:
int base;
HFONT font;
void printText (const char *input, ...){
char text[256];
va_list ap;
if (input == NULL) return;
va_start(ap, input);
vsprintf(text, input, ap);
va_end(ap);
glPushAttrib(GL_LIST_BIT);
glListBase(base - 32);
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
glPopAttrib();
}
void killFont(){
glDeleteLists(base, 96);
}
void gui_drawtext(char *text, Window *win){
HFONT oldfont;
if (win){
wglMakeCurrent(win->hdc, win->hrc);
oldfont = (HFONT)SelectObject (win->hdc, font);
wglUseFontBitmaps (win->hdc, 32, 96, base);
SelectObject (win->hdc, oldfont);
glRasterPos2f(20.0F, 0.0F);
printText(text);
killFont();
}
}
void buildLargeFont(){
base = glGenLists(96);
font = CreateFont(20, 0, 0, 0, 100, FALSE, FALSE, FALSE,
ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,
ANTIALIASED_QUALITY, FF_DONTCARE|DEFAULT_PITCH, "Comic Sans MS");
}
I suspect that this implementation is very slow though, because wglUseFontBitmaps() is called on every frame when text is drawn. Does anyone know how to make this faster ? Keep in mind that I have to use multiple windows, with each window its own DC and RC;