积累系统性知识
积聚技术精华
  首页    个人中心    撰写积文    建立课题    订立目标    整理积文    管理课题    管理目标    技能Get    代码积累 
OpenGL显示中文
error997 (error997)    2014-11-20 20:31:14      目标    课题
   OpenGL显示中文函数
   
切换到: 纯代码  
   
   void glDrawString(unsigned char *str)
...{
    GLYPHMETRICSFLOAT pgmf[1];

    HDC hDC=wglGetCurrentDC();
    HFONT hFont;
    LOGFONT lf ;
    memset(&lf,0,sizeof(LOGFONT));
    lf.lfHeight = 1 ;
    lf.lfWidth = 0 ;
    lf.lfEscapement = 0 ;
    lf.lfOrientation = 0 ;
    lf.lfWeight = FW_NORMAL ;
    lf.lfItalic = FALSE ;
    lf.lfUnderline = FALSE ;
    lf.lfStrikeOut = FALSE ;
    lf.lfCharSet = GB2312_CHARSET ;
    lf.lfOutPrecision = OUT_TT_PRECIS ;
    lf.lfClipPrecision= CLIP_DEFAULT_PRECIS ;
    lf.lfQuality = PROOF_QUALITY ;
    lf.lfPitchAndFamily = VARIABLE_PITCH | TMPF_TRUETYPE | FF_MODERN ;
    lstrcpy (lf.lfFaceName, "宋体") ;
    hFont = CreateFontIndirect(&lf);
    //设置当前字体
    SelectObject(wglGetCurrentDC(),hFont);


    DWORD dwChar;
    int ListNum;
    for(size_t i=0;i<strlen((char *)str);i++)
    ...{
        if(IsDBCSLeadByte(str[i]))
        ...{
            dwChar=(DWORD)((str[i]<<8)|str[i+1]);
            i++;
        }
        else
            dwChar=str[i];
        ListNum=glGenLists(1);
        wglUseFontOutlines(hDC,dwChar,1,ListNum,0.0,0.1f,WGL_FONT_POLYGONS,pgmf);
        glCallList(ListNum);
        glDeleteLists(ListNum,1);
    }
}

   

   使用
   
切换到: 纯代码  
   
   byte cstr[]=...{"中文测试"};
 glDrawString(cstr);


转自 http://blog.csdn.net/y___y/article/details/1417416
(+0)技能Get

建议楼主:搜索关键字 |参考其他资源 |回复 |追问
  error997(error997):   个人中心    课题    目标    代码积累