using multiple fonts on the fly

hello i want to use multiple / different font styles in my application duriong run time . how can i achieve it . i used display list to make different fonts . but when i call first display list and switch to 2nd the text vanishes after some time . this mightbe due to loss of memory how can i avhiece this
secondly how can i get different textures of fonts on the web that is of different font styles etc so tha i can usr texture fonts and change the texture whenever i need different font
can they be cahnge during flyoutthat is when applicaton is running and text is changing
thanks

Hi,

“but when i call first display list and switch to 2nd the text vanishes after some time.”

I am not sure what would cause it to disappear over time, but could you give some pseudo code (or actual code) that shows how you are using your display list and textures.

"secondly how can i get different textures of fonts on the web that is of different font styles etc so tha i can usr texture fonts and change the texture whenever i need different font "

Are you using 3D fonts (textured meshes) or 2D fonts (by use of textures)?

“can they be cahnge during flyoutthat is when applicaton is running and text is changing”

Sure they can, however currently I am not sure how you are implementing your fonts so I cannot recommend a method yet.

Simply, why don’t you use 2 differents textures for the font ?

Sounds like you have multiple display lists, one for each font. That’s good.

But it sounds like you’re not handling the ModelView matrix stack properly when displaying the fonts successively.

It’s about the only thing that would explain why the first text disappears after ‘some time’.

Can you boil down the code to a small sample that shows the problem and post a link to that sample code for review?

the code

// Our Bitmap Font1
GLvoid BuildFont_1(GLvoid)
{
HFONT font; // Windows Font ID
base = glGenLists(96); // Storage For 96 Characters ( NEW )

font_size = -11;

font = CreateFont( font_size, // Height Of Font
0, // Width Of Font
0, // Angle Of Escapement
0, // Orientation Angle
FW_NORMAL, // Font Weight
FALSE, // Italic
FALSE, // Underline
FALSE, // 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
“Ariel”); // Font Name

SelectObject(hDC, font);

wglUseFontBitmaps(hDC, 32, 96, base); // Builds 96 Characters Starting At Character 32
}

// bitmap font 2
GLvoid BuildFont_2(GLvoid)
{
HFONT font; // Windows Font ID

base = glGenLists(96); // Storage For 96 Characters ( NEW )

font_size = -15;

font = CreateFont( font_size, // Height Of Font
0, // Width Of Font
0, // Angle Of Escapement
0, // Orientation Angle
FW_NORMAL, // Font Weight
FALSE, // Italic
FALSE, // Underline
FALSE, // 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
“Courier New”); // Font Name

SelectObject(hDC, font);

wglUseFontBitmaps(hDC, 32, 96, base); // Builds 96 Characters Starting At Character 32
}

GLvoid KillFont(GLvoid) // Delete The Font
{
glDeleteLists(base, 96); // Delete All 96 Characters ( NEW )
}

GLvoid glPrint(const char *fmt, …) // Custom GL “Print” Routine
{
char text[256]; // Holds Our String
va_list ap;

if (fmt == NULL) // If There’s No Text
return;

va_start(ap, fmt); // Parses The String For Variables
vsprintf(text, fmt, ap); // And Converts Symbols To Actual Numbers
va_end(ap);

glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits ( NEW )
glListBase(base - 32);

glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // Draws The Display List Text ( NEW )
glPopAttrib(); // Pops The Display List Bits

}

i am calling the function buildfont_1 whenever i have to print using font1 before glprint function along with glRasterPos()and similarly i call buildfont_2 for font2
can any body help me out

Hello,

I still need to look over what you sent, but the first thing I noticed is that you don’t delete your font before building a new one. If you call BuildFont_1 and BuildFont_2 before every glPrint, then you may run out of display list storage after some “time”.

Also, you may want to put the two BuildFont’s together into one function which takes parameters for the “base” and font name. I think you should be able to have multiple fonts at a time. I will reply again once I try this myself.

One last thing, it is not efficient to build and delete fonts every time you want to print some text, you should store the font for as long as it will be needed.

hello
how can i erase my old display list and use new and then erase that and use previous one please provide me with some help .i am using it to dispaly multiple fonts on a same screen
also
how can i make a texture of different fonts

thanks

Call your “KillFont” function. That will delete your font display list. To load a new font, call your “BuildFont” function with a different font name. Also, your “KillFont” function shows you how to delete 96 display lists (used by your font). Also check the documentation on glDeleteLists and glGenLists for more information.

GLvoid KillFont(GLvoid) // Delete The Font
{
glDeleteLists(base, 96); // Delete All 96 Characters ( NEW )
}

And remember, that you should not delete and build a new font set every time you want to print something (keep the font “built” until it will no longer be used).

how can i make a texture of different fonts

I will get back to you on that later.

hello
i tried to use killfont() function but it doesn’t prove to be ok. i still don’t know how to get away with this problem

Hello,

Put a sample of your main function so I can see how you use your fonts. KillFont MUST work, if it doesn’t then there must be a problem in the way you create and use the fonts.

[This message has been edited by hkyProgrammer88 (edited 06-05-2003).]