NeHe OpenGL Lesson13 – Bitmap Fonts

screen_shot7-300x236 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(base32);                                
    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.

转载于:https://www.cnblogs.com/open-coder/archive/2012/08/23/2653357.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值