OpenGL显示中文-Unicode版本
2014-02-24 15:04
411 查看
void GLFont::Print3DTextW(wchar_t *string, float z)
{
HDC hDC =
wglGetCurrentDC();
HFONT
hOldFont=(HFONT)::SelectObject(hDC,m_hFont);
int
nListNum;
DWORD
dwChar;
GLYPHMETRICSFLOAT
pgmf[1];
glPushMatrix();
glDisable(GL_LIGHTING);
for(int i = 0; i
<wcslen(string); i++)
{
dwChar =
string[i];
nListNum =
glGenLists(1);
wglUseFontOutlinesW(
hDC,
dwChar,
1,
nListNum,
0.0f,
z,
WGL_FONT_POLYGONS,
pgmf
);
glCallList(nListNum);
glDeleteLists(nListNum,
1);
}
glEnable(GL_LIGHTING);
glPopMatrix();
::SelectObject(hDC,hOldFont);
}
其实Ansi版本的处理比Unicode的要复杂,因为需要考虑中文的多个字节,如下所示:
for(int i = 0; i <
strlen(string); i++)
{
if(
IsDBCSLeadByte((BYTE)pChar[i])
)
{
dwChar=(DWORD)((pChar[i]<<8)|pChar[i+1]);
i++;
}
else
dwChar =
pChar[i];
nListNum =
glGenLists(1);
wglUseFontOutlines(
hDC,
dwChar,
1,
nListNum,
0.0f,
z,
WGL_FONT_POLYGONS,
pgmf
);
glCallList(nListNum);
glDeleteLists(nListNum,
1);
}
其实Ansi版本的处理反而更复杂一些,因为需要考虑中文的多字节问题,如下所示:
for(int i = 0; i <
strlen(string); i++)
{
if(
IsDBCSLeadByte((BYTE)pChar[i])
)
{
dwChar=(DWORD)((pChar[i]<<8)|pChar[i+1]);
i++;
}
else
dwChar =
pChar[i];
nListNum =
glGenLists(1);
wglUseFontOutlines(
hDC,
dwChar,
1,
nListNum,
0.0f,
z,
WGL_FONT_POLYGONS,
pgmf
);
glCallList(nListNum);
glDeleteLists(nListNum,
1);
}
{
HDC hDC =
wglGetCurrentDC();
HFONT
hOldFont=(HFONT)::SelectObject(hDC,m_hFont);
int
nListNum;
DWORD
dwChar;
GLYPHMETRICSFLOAT
pgmf[1];
glPushMatrix();
glDisable(GL_LIGHTING);
for(int i = 0; i
<wcslen(string); i++)
{
dwChar =
string[i];
nListNum =
glGenLists(1);
wglUseFontOutlinesW(
hDC,
dwChar,
1,
nListNum,
0.0f,
z,
WGL_FONT_POLYGONS,
pgmf
);
glCallList(nListNum);
glDeleteLists(nListNum,
1);
}
glEnable(GL_LIGHTING);
glPopMatrix();
::SelectObject(hDC,hOldFont);
}
其实Ansi版本的处理比Unicode的要复杂,因为需要考虑中文的多个字节,如下所示:
for(int i = 0; i <
strlen(string); i++)
{
if(
IsDBCSLeadByte((BYTE)pChar[i])
)
{
dwChar=(DWORD)((pChar[i]<<8)|pChar[i+1]);
i++;
}
else
dwChar =
pChar[i];
nListNum =
glGenLists(1);
wglUseFontOutlines(
hDC,
dwChar,
1,
nListNum,
0.0f,
z,
WGL_FONT_POLYGONS,
pgmf
);
glCallList(nListNum);
glDeleteLists(nListNum,
1);
}
其实Ansi版本的处理反而更复杂一些,因为需要考虑中文的多字节问题,如下所示:
for(int i = 0; i <
strlen(string); i++)
{
if(
IsDBCSLeadByte((BYTE)pChar[i])
)
{
dwChar=(DWORD)((pChar[i]<<8)|pChar[i+1]);
i++;
}
else
dwChar =
pChar[i];
nListNum =
glGenLists(1);
wglUseFontOutlines(
hDC,
dwChar,
1,
nListNum,
0.0f,
z,
WGL_FONT_POLYGONS,
pgmf
);
glCallList(nListNum);
glDeleteLists(nListNum,
1);
}
相关文章推荐
- xcode 4.3版本 在连接上ipad后,程序用nslog不显示中文的解决办法
- 【python在git bash下的中文显示】 UnicodeEncodeError: 'ascii' codec can't encode characters in position ...
- C++unicode中文显示
- python2 list的unicode用中文显示
- python list unicode转中文显示
- 让使用非东来版本9800支持中文显示,非输入/菜单
- WinSCP(版本5.7.6)中文文件名显示乱码
- 中文账号显示问题 【UTF-8 转换成 多字节 Unicode】
- 使用OPENGL显示中文的类
- IOS中 打印字典、数组时 直接显示中文(而不是显示Unicode字符)
- Eclipse中Properties中文显示不自动转成Unicode
- eclipse中文注释显示为unicode
- C语义char*显示中文---ASCII、DBCS、Unicode三种编码---char* CString string区别
- SDL入门教程(十):2、直接通过Unicode让SDL显示中文
- spring mvc 4.x 版本在返回给ajax调用的json数据时候,出现中文显示???的处理方法
- python list unicode转中文显示
- Python写入txt文件中的中文Unicode无法显示为中文
- 从4.8.5版本升级到FastReport 4.10.1后,中文菜单有乱码,有的没有显示
- xcode 4.3版本 在连接上ipad后,程序用nslog不显示中文的解决办法
- MySQL丨5.6版本插入中文显示问号解决方法