Bitmap Fonts

Started by
2 comments, last by nife 19 years, 5 months ago
Using the bitmap font tutorial (#13), I created a font object to handle font creation and printing, but... When I create instances of this object and try to print lines of text, it doesn't work. In order for it to work, I have to make the font object call wglUseFontBitmaps() every time I want it to print something. Is there any way I can prevent this? Building the font every time is pretty CPU-intensive. Thanks.
Advertisement
You shouldn't be creating instances of your object every time you create a message. Just create one global font object, initialize it at the start of the application, and just call its print() function every time you want to print something. If you want to be able to post messages by creating temporary objects, create a separate FontMessage class that contains a position, text message, and maybe a color. Then have your associated font class draw it. But before you create any new classes and redesign your layout, get it working the way you have it. If you cant make the font object global, make the font data (the windows bitmap and openGL display list stuff) static, that way, even if instances of the font object are deleted, you still have the font data to print messages from. Anyway, I hope that helps. Good luck!
Thanks for the reply... let me specify my situation a little bit.

I'm creating some classes for a user interface in a 3D application... I have a window class (the windows are essentially just polygons), and the window class has a display function that draws the polygon for the window, and then draws the bitmap text on top of it. The window class has a font object that I initialize once when the window is created and use in the display function for the window.

The problem is, in the window display function, I have to call the SelectObject() and wglUseFontBitmaps() functions (as in tutorial #13) every time the display function is called or the font object will print a blank line.

What it seems like is that the font object must be initialized within the same function that it's used, or it won't work. Any additional thoughts?
Well, first of all you shouldn't be using bitmap fonts. Take a look at your fps with/without and you'll see what I mean.
Second, if you still want to use them, then the method that works is like so:
// Creating the fontint base = glGenLists(96);HFONT font = CreateFont(-10, 0, 0, 0, FW_NORMAL, 0, 0, 0, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_DONTCARE | DEFAULT_PITCH, "Verdana");SelectObject(dc, font);wglUseFontBitmaps(dc, 32, 96, base);// Game loop where the font is displayedglPushAttrib(GL_LIST_BIT);glListBase(base - 32);glRasterPos2f(10, 470);glCallLists(strlen(s), GL_UNSIGNED_BYTE, s);glPopAttrib();// Destroying the fontglDeleteLists(base, 96);DeleteObject(font);wglMakeCurrent(NULL, NULL);
Killers don't end up in jailThey end up on a high-score!

This topic is closed to new replies.

Advertisement