• Advertisement
Sign in to follow this  

Bitmap Fonts

This topic is 4834 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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 font
int 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 displayed
glPushAttrib(GL_LIST_BIT);
glListBase(base - 32);
glRasterPos2f(10, 470);
glCallLists(strlen(s), GL_UNSIGNED_BYTE, s);
glPopAttrib();

// Destroying the font
glDeleteLists(base, 96);
DeleteObject(font);
wglMakeCurrent(NULL, NULL);


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement