【VC开源代码栏目提醒】:以下是网学会员为您推荐的VC开源代码-GlGlyphList.cpp,希望本篇文章对您学习有所帮助。
// GlGlyphList.cpp: implementation of the CGlGlyphList class.
// OpenGL字形表类实现
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Image.h"
#include "GlGlyphList.h"
#include "gl/gl.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// 构造函数/析构函数
//////////////////////////////////////////////////////////////////////
CGlGlyphList::CGlGlyphList()
{
m_nNum = 0;
m_pList= NULL;
}
CGlGlyphList::~CGlGlyphList()
{
if(m_pList) delete m_pList;
}
/////////////////////////////////////////////////////////////////////
// 函数名 : CGlGlyphList::ConvertString
// 说 明 : 将字符串转换为OpenGL字形表,存放到m_pList中
// 返回值 : BOOL ,如果成功返回TRUE,否则返回FALSE
// 参数表 :
// LPCTSTR szText : 要串换的字符串
// HDC hdc : 转换字形时所使用的设备环境句柄,含有想使用的字体
// float fExtru : 字形的深度(z方向),缺省为0.1
// float fDev : 字形的精度(>=0),缺省为0.0
// BOOL bUsePolygon : 填充方式,TRUE=实心字形(缺省),FALSE=空心字形
BOOL CGlGlyphList::ConvertString(
LPCTSTR szText,
HDC hdc,
float fExtru/*=0.1*/,
float fDev/*=0.0*/,
BOOL bUsePolygon/*=TRUE*/)
//float fExtru=0.1,
//float fDev=0.0,
//BOOL bUsePolygon=TRUE)
{
CString strText = szText;
int nStrLen = strText.GetLength();
if(nStrLen == 0) return TRUE;
USHORT* pList = new USHORT[nStrLen];
WORD nCharCode;
int nFormat = bUsePolygon ? WGL_FONT_POLYGONS : WGL_FONT_LINES;
//for(int i=0; i<nStrLen; i++) {
for(int i=0; i<nStrLen; i++) {
TCHAR c = strText[i];
#ifndef UNICODE //支持DBCS
if(::IsDBCSLeadByte(c)) { //判断是否双字节字符的其实标志
nCharCode = MAKEWORD(strText[++i], c);
}
else
#endif
nCharCode = (WORD)c;
int nListNo = glGenLists(1);
//生成一个字符的字形:
if(!wglUseFontOutlines(hdc, nCharCode, 1, nListNo,
//fDev, fExtru, nFormat, NULL) && m_nNum>0) {
fDev, fExtru, nFormat, NULL) && m_nNum>0) {
delete pList;
m_nNum = 0;
return FALSE;
}
pList[m_nNum] = nListNo; //将字形加入列表中
m_nNum ++;
}
m_pList = new USHORT[m_nNum];
memcpy(m_pList, pList, m_nNum*sizeof(USHORT));
delete pList;
return TRUE;
}//CGlGlyphList::ConvertString()定义结束
// GlGlyphList.cpp文件结束
//////////////////////////////////////////////////////////////////////
上一篇:
GifToBmp.cpp
下一篇:
让我掉下眼泪的