This demo shows us how to display some characters on the screen with OpenGL bitmap fonts. This is a very useful feature that we could used to display some text, debug information, fps or even menu content on the screen. Those staffs are not part of 3D scene, but usually head up display(HUD for short). Some very cool effect could be made by Flash, then those flashes could be integrated into the game as the menu pages or elements. Well, Scaleform does that.
Bitmap fonts use any of your computers built in fonts. Bitmaps font’s are 2D scalable fonts, they can not be rotated. They always face forward. Of course you could make your own text with texture mapping. But obviously, bitmap fonts has more flexibility than text texture mapping.
Go though the source code, display list and wglUseFontBitmaps works together to make the 96 characters. And one some platform specific code there: GDI device context object and font objects. Set the fonts object to the GDI device content before you create the bitmap fonts.
Here are the funny thing when draw the text on the screen:
GLvoid glPrint(const char *fmt, …) { char text[256]; va_list ap; if (fmt == NULL) return; va_start(ap, fmt); vsprintf(text, fmt, ap); va_end(ap); glPushAttrib(GL_LIST_BIT); glListBase(base – 32); glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); glPopAttrib(); }
One point is that the parameters for this function are not fixed. It does as you see with printf function.
The other point is that draw bitmap fonts text is the same as call display list. No special operation should be take care of. Here are the code the call this function:
glRasterPos2f(-0.45f+0.05f*float(cos(cnt1)), 0.32f*float(sin(cnt2))); glPrint(“Active OpenGL Text With NeHe – %7.2f”, cnt1);
Here glRasterPos2f used to locate where the text will be display. This function locate the position in the raster space instead of world space.
The full source code could be downloaded from here.
本文介绍如何使用OpenGL的Bitmap字体在屏幕上显示字符,这是显示文本、调试信息、FPS或菜单内容的有效方式。Bitmap字体利用计算机内置字体,适用于2D场景且不可旋转。文中详细解释了如何通过源代码、显示列表和wglUseFontBitmaps实现这一功能。
9875

被折叠的 条评论
为什么被折叠?



