資源簡(jiǎn)介
OpenGl文字顯示c++類,包括*.h和*.cpp,可顯示中英文,已優(yōu)化,速度很快。

代碼片段和文件信息
#include?“stdafx.h“
#include?“glText.h“
#include?
#include?
#include?
#include?
CGlFont::CGlFont()
{
m_hFont=NULL;
InitFont(“宋體“);
m_X?=?0;
m_Y?=?0;
m_dHeight?=?0;
m_fExtrusion?=?0.1f;
m_rotateTheta?=?0.0;
?m_iDisplayList?=?0;
?m_red?=255;
?m_blue?=?255;
?m_green?=?255;
}
CGlFont::~CGlFont()
{
}
LOGFONT?CGlFont::GetLogFont()
{
LOGFONT?lf;
Getobject(m_hFontsizeof(LOGFONT)&lf);
return?lf;
}
void?CGlFont::DeleteFont()
{
if(m_hFont)
{
Deleteobject(m_hFont);
m_hFont=NULL;
}
}
bool?CGlFont::InitFont(LOGFONT?&lf)
{
DeleteFont();
m_hFont=CreateFontIndirect(&lf);
if(?m_hFont?)return?true;
else?return?false;;
}
bool?CGlFont::InitFont(char?*fontName)
{
DeleteFont();
m_hFont?=?CreateFont(
-16 // 0 // 0 // 0 // FW_BOLD // FALSE // FALSE // FALSE // GB2312_CHARSET // OUT_TT_PRECIS // CLIP_DEFAULT_PRECIS // ANTIALIASED_QUALITY // FF_DONTCARE|DEFAULT_PITCH // fontName); // if(m_hFont)return?true;
else?return?false;
}
void?CGlFont::Draw2DText(char?*string)
{
if(strlen(string)<=0)return;
//HDC?hDC=wglGetCurrentDC();
HDC?hDC?=?::CreateCompatibleDC(NULL);
HFONT?hOldFont=NULL;
hOldFont=(HFONT)Selectobject(hDCm_hFont);
if(!hOldFont)
{
return;
}
glRasterPos2f(m_X?m_Y);
DWORD?dwChar;
int?ListNum;
for(size_t?i=0;i {
if(IsDBCSLeadByte(string[i]))
{
dwChar=((unsigned?char)string[i])*0x100+(unsigned?char)string[i+1];
i++;
}
else
{
dwChar=string[i];
}
ListNum=glGenLists(1);
wglUseFontBitmaps(hDCdwChar1ListNum);
glCallList(ListNum);
glDeleteLists(ListNum1);
}
Selectobject(hDChOldFont);
::DeleteDC(hDC);
}
map??CGlFont::m_sglFontList;
void?CGlFont::Draw3DText(const?char?*string)
{
if(strlen(string)<=0)
return;
GLYPHMETRICSFLOAT?pgmf[1];
HDC?hDC=wglGetCurrentDC();
//設(shè)置當(dāng)前字體
HFONT?hOldFont=NULL;
hOldFont=(HFONT)Selectobject(hDCm_hFont);
if(!hOldFont)
{
return;
}
DWORD?dwChar;
int?ListNum;
int?iNum=strlen((char?*)string);
m_iDisplayList=glGenLists(1);
glPushMatrix();
for(size_t?i=0;i {
if(IsDBCSLeadByte(string[i]))//是否為中文
{
dwChar=((unsigned?char)string[i])*0x100+(unsigned?char)string[i+1];
i++;
}
else
{
dwChar=string[i];
}
//不同的文字在文字描述表中只出現(xiàn)一次,如“我是中國(guó)中國(guó)”,重復(fù)的中和國(guó)只出現(xiàn)一次,這樣大大提高了速度
if?(m_sglFontList.find(dwChar)?==?m_sglFontList.e
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件???????1258??2010-08-24?10:01??glText.h
?????文件???????4148??2010-08-24?10:01??glText.cpp
-----------?---------??----------?-----??----
?????????????????5406????????????????????2
評(píng)論
共有 條評(píng)論