PDA

View Full Version : 2D font display problem!!!!



HanWu
01-17-2007, 01:04 AM
I am having a big problem here. I need to dynamically change the font size in my program. I will need to use a pixel font rather than texture font or 3D font due to some reason.
My problem is every time I call this BuildFont sometime it will return a correct font ( meaning I am able to display the text correctly) but sometime not able to display the text. The code snippet is as follow.

public int BuildFont(){
int listbase;
listbase = glGenLists(96); //96 individual lists

HFONT font; //native windows object.
HFONT oldfont; //native windows object.

font = CreateFont(...bunch of parameters specifying the font to load); //native windows func.

oldfont = SelectObject(hdc, font);
//handle to device context
//i'll assume that 32 = offset from first ASCII character
//96 = size of list
//the opengl list(s)
wglUseFontBitmaps(hdc, 32, 96, listbase);
SelectObject(hdc, oldfont);
DeleteObject(font);

return listbase;
}

// display Text
char *string;
glPushAttrib(GL_LIST_BIT);
glListBase(listbase - 32); //32 offset backwards since we offset it forwards
glCallLists(strlen(string), GL_UNSIGNED_BYTE, string);
glPopAttrib();
// display Text end.

I did the checking with calling the BuildFont function 3 times.
I have checked the listbase and the value are keep increasing (every call of BuildFont the listbase will increase by 96) so the glGenLists should works correctly. But how come some of the returned display list indices can work but some cannot work? I really have no idea. Please help!!!

Joseph Steel
01-17-2007, 10:00 AM
I have had problems in the past with calling wglUseFontBitmaps() and found the solution was to call this twice! Yes I know it sounds bizarre but there you go!

HanWu
01-17-2007, 04:40 PM
Thanks, it sounds bizarre but it really solve my problem.