OpenGL入门笔记(十二)

成员变量区:
    GLuint 
base ;
    GLfloat cnt1;
    GLfloat cnt2;

成员函数区:
GLvoid COpenGLDemoView::glPrint(
const   char   * fmt, )                     //  Custom GL "Print" Routine
{
    
char        text[256];                                // Holds Our String
    va_list        ap;                                        // Pointer To List Of Arguments

    
if (fmt == NULL)                                    // If There's No Text
        return;                                            // Do Nothing

    va_start(ap, fmt);                                    
// Parses The String For Variables
        vsprintf(text, fmt, ap);                        // And Converts Symbols To Actual Numbers
    va_end(ap);                                            // Results Are Stored In Text

    glPushAttrib(GL_LIST_BIT);                            
// Pushes The Display List Bits
    glListBase(base);                                // Sets The Base Character to 32
    glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);    // Draws The Display List Text
    glPopAttrib();                                        // Pops The Display List Bits
}


GLvoid COpenGLDemoView::BuildFont(GLvoid)
{
    HFONT    font;                                        
// Windows Font ID
    HFONT    oldfont;                                    // Used For Good House Keeping

    
base = glGenLists(96);                                // Storage For 96 Characters

    font 
= CreateFont(    -24,                            // Height Of Font
                        0,                                // Width Of Font
                        0,                                // Angle Of Escapement
                        0,                                // Orientation Angle
                        FW_BOLD,                        // Font Weight
                        FALSE,                            // Italic
                        FALSE,                            // Underline
                        FALSE,                            // Strikeout
                        ANSI_CHARSET,                    // Character Set Identifier
                        OUT_TT_PRECIS,                    // Output Precision
                        CLIP_DEFAULT_PRECIS,            // Clipping Precision
                        ANTIALIASED_QUALITY,            // Output Quality
                        FF_DONTCARE|DEFAULT_PITCH,        // Family And Pitch
                        "Courier New");                    // Font Name
    HDC hDC = ::GetDC(this->m_hWnd);
    oldfont 
= (HFONT)SelectObject(hDC, font);           // Selects The Font We Want
    wglUseFontBitmaps(hDC, 0255base);                // Builds 96 Characters Starting At Character 32
    SelectObject(hDC, oldfont);                            // Selects The Font We Want
    DeleteObject(font);                                    // Delete The Font
}

GLvoid COpenGLDemoView::KillFont(GLvoid)
{
    glDeleteLists(
base,96);
}

GLvoid COpenGLDemoView::KillFont(GLvoid)
{
    glDeleteLists(
base,96);
}


int  COpenGLDemoView::DrawGLScene()                                   
{// Here's Where We Do All The Drawing
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    // Clear Screen And Depth Buffer
    glLoadIdentity();                                    // Reset The Current Modelview Matrix
    glTranslatef(0.0f,0.0f,-1.0f);                        // Move One Unit Into The Screen
    
// Pulsing Colors Based On Text Position
    glColor3f(1.0f*float(cos(cnt1)),1.0f*float(sin(cnt2)),1.0f-0.5f*float(cos(cnt1+cnt2)));
    
// Position The Text On The Screen
    glRasterPos2f(-0.45f+0.05f*float(cos(cnt1)), 0.32f*float(sin(cnt2)));
     glPrint(
"Active OpenGL Text - %7.2f", cnt1);    // Print GL Text To The Screen
    cnt1+=0.051f;                                        // Increase The First Counter
    cnt2+=0.005f;                                        // Increase The First Counter
    return TRUE;                                        // Everything Went OK
                                      
// Everything Went OK
}



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值