在View窗口中添加顯示FTGL字體

以MFC界面爲例進行講解:MFC工程名爲 AddFont

在配置好Opengl環境的MFC工程中,在AddFontView.h文件中添加#include <font/FTGLPixmapFont.h>文件,
還有相應的lib添加

.h文件聲明FTGLPixmapFont* freeTypeFont;   

CAddFontView::CAddFontView()
{
    // TODO: 在此處添加構造代碼

    loadproperty = true;
    loadvvo = true;
    char filePath[256]={0};
    sprintf(filePath, "C:\\WINDOWS\\Fonts\\simhei.ttf");
    freeTypeFont = new FTGLPixmapFont(filePath);
    if(freeTypeFont == NULL)
    {
        char buf[] = "Font C:\\WINDOWS\\Fonts\\simhei.ttf can not be fond.\r\n";
        printf("%s", buf);
        exit(0);
    }
    else
    {
        freeTypeFont->FaceSize(20);
        freeTypeFont->CharMap(ft_encoding_unicode);
    }    
}

CAddFontView::~CAddFontView()
{
    
    if (freeTypeFont != NULL)
    {
        delete freeTypeFont;
        freeTypeFont = NULL;
    }    
}

void CAddFontView::DrawScene()
{   

     wchar_t str0[250]=L"海平面高度I/K:";
     glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
     glWindowPos2iARB(50, 80);
     glEnable(GL_BLEND);
     glEnable(GL_ALPHA_TEST);
     glAlphaFunc(GL_GREATER ,0.5f);
    freeTypeFont->FaceSize(20);
     freeTypeFont->Render(str0);
 
     string sealevel_h = Convert_float2str(updown_value);    
     const char *sealevelheight=sealevel_h.c_str();    
     glWindowPos2iARB(220, 80);    
     freeTypeFont->Render(sealevelheight);
 
     wchar_t str2[250]=L"海浪高度O/L:";
     glWindowPos2iARB(50, 50);
     freeTypeFont->Render(str2);    
 
     string wave_h = Convert_float2str(waveheight_value);    
     const char *waveheight=wave_h.c_str();    
     glWindowPos2iARB(220, 50);      
     freeTypeFont->Render(waveheight);
 
     wchar_t str4[250]=L"相機操作:";
     glWindowPos2iARB(50, 200);
    freeTypeFont->FaceSize(15);
     freeTypeFont->Render(str4);
 
     wchar_t str5[250]=L"WSAD/上下左右移動";        
     glWindowPos2iARB(50, 180);
     freeTypeFont->Render(str5);
 
     wchar_t str6[250]=L"Insert Delete/左右旋轉";
     glWindowPos2iARB(50, 160);   
     freeTypeFont->Render(str6);
 
     wchar_t str7[250]=L"H/復位";
     glWindowPos2iARB(50, 140);  
     freeTypeFont->Render(str7);
 
     glDisable(GL_ALPHA_TEST);
     glDisable(GL_BLEND);     
    
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章