OpenGL中的汉字显示

None.gif void  COpenGLDemoView::glDrawString(unsigned  char   * str)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    GLYPHMETRICSFLOAT pgmf[
1];
InBlock.gif    HDC hDC
=wglGetCurrentDC();
InBlock.gif    HFONT hFont;
InBlock.gif    LOGFONT lf ;
InBlock.gif    memset(
&lf,0,sizeof(LOGFONT));
InBlock.gif    lf.lfHeight 
= 1 ;
InBlock.gif    lf.lfWidth 
= 0 ;
InBlock.gif    lf.lfEscapement 
= 0 ;
InBlock.gif    lf.lfOrientation 
= 0 ;
InBlock.gif    lf.lfWeight 
= FW_NORMAL ;
InBlock.gif    lf.lfItalic 
= FALSE ;
InBlock.gif    lf.lfUnderline 
= FALSE ;
InBlock.gif    lf.lfStrikeOut 
= FALSE ;
InBlock.gif    lf.lfCharSet 
= GB2312_CHARSET ;
InBlock.gif    lf.lfOutPrecision 
= OUT_TT_PRECIS ;
InBlock.gif    lf.lfClipPrecision
= CLIP_DEFAULT_PRECIS ;
InBlock.gif    lf.lfQuality 
= PROOF_QUALITY ;
InBlock.gif    lf.lfPitchAndFamily 
= VARIABLE_PITCH | TMPF_TRUETYPE | FF_MODERN ;
InBlock.gif    lstrcpy (lf.lfFaceName, 
"宋体") ;
InBlock.gif    hFont 
= CreateFontIndirect(&lf);
InBlock.gif    
//设置当前字体
InBlock.gif
    SelectObject(wglGetCurrentDC(),hFont);
InBlock.gif    DWORD dwChar;
InBlock.gif    
int ListNum;
InBlock.gif    
for(size_t i=0;i<strlen((char *)str);i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
if(IsDBCSLeadByte(str[i]))
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            dwChar
=(DWORD)((str[i]<<8)|str[i+1]);
InBlock.gif            i
++;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
else
InBlock.gif            dwChar
=str[i];
InBlock.gif        ListNum
=glGenLists(1);
InBlock.gif    wglUseFontOutlines(hDC,dwChar,
1,ListNum,0.0,0.1f,WGL_FONT_POLYGONS,pgmf);
InBlock.gif        glCallList(ListNum);
InBlock.gif        glDeleteLists(ListNum,
1);
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

None.gif int  COpenGLDemoView::DrawGLScene()                                   
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {// Here's Where We Do All The Drawing
InBlock.gif
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    // Clear Screen And Depth Buffer
InBlock.gif
    glLoadIdentity();                                    // Reset The Current Modelview Matrix
InBlock.gif
    glTranslatef(-2.5f,0.0f,-10.0f);                        // Move One Unit Into The Screen
InBlock.gif
    unsigned char str[] = "你好,中国";
InBlock.gif    
this->glDrawString(str);
InBlock.gif    
return TRUE;                                        // Everything Went OK
InBlock.gif                                      
// Everything Went OK
ExpandedBlockEnd.gif
}

效果如图所示:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />


200782501.jpg
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值