我查了MSDN,里面说要先用MutiByteToWideChar函数将矢量字体转化成UniCode字符,再用wglFontOutLine生成显示列表
但我总是不成功,哪位大侠把代码贴一下!!

解决方案 »

  1.   

    这个很简单啊,你只需要显示二维的文字就可以了,将不同颜色的地几个相同的字显示在相应的地方。
           ^^^^^^^^^^^^^^^^
           ^^^^^^^^^^^^^^^^
                  ^^^&&&&&&
                  ^^^&
                  ^^^&
                  ^^^&
                  ^^^&
                  ^^^&
      

  2.   

    GlGlyphList.h// GlGlyphList.h: interface for the CGlGlyphList class.
    // OpenGL字形表类接口
    //////////////////////////////////////////////////////////////////////#if !defined(AFX_GLGLYPHLIST_H_INCLUDED_)
    #define AFX_GLGLYPHLIST_H_INCLUDED_#if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000class CGlGlyphList //OpenGL字形表类
    {
    //Constructor/Destructor:
    public:
    CGlGlyphList();
    virtual ~CGlGlyphList();
    //Attribute:
    public:
    int m_nNum; //表中的字形数
    USHORT* m_pList; //字形表
    //Operation:
    public:
    //将字符串串换为OpenGL字形表,存放到m_pList中
    BOOL ConvertString(LPCTSTR szText, HDC hdc,
    float fExtru = 0.1f, float fDev = 0.0f, BOOL bUsePolygon=TRUE);
    };#endif // !defined(AFX_GLGLYPHLIST_H_INCLUDED_)//GlGlyphList.h文件结束
    //////////////////////////////////////////////////////////////////////
    GlGlyphList.cpp
    // GlGlyphList.cpp: implementation of the CGlGlyphList class.
    // OpenGL字形表类实现
    //////////////////////////////////////////////////////////////////////#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*/)
    {
    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++) {
    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) {
    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文件结束
    //////////////////////////////////////////////////////////////////////
    >应用举例:#include "gl/gl.h"
    #include "GlGlyphList.h"...//初始化OpenGL及设备环境
    ...
    CDC* pDC = GetDC();
    CFont font;
    font.CreateFont(...,GB2312_CHARSET,..., "宋体");
    CFont* pOldFont = pDC->SelectObject( &font );
    ...//构造字形表对象:
    CString strText = _T("OpenGL真麻烦!");
    CGlGlyphList glyphList;
    glyphList.ConvertString( strText, pDC->GetSafeHdc() );
    pDC->SelectObject( pOldFont );//OpenGL变换
    ...//在OpenGL窗口中输出字形
    glCallLists(glyphList.m_nNum, GL_UNSIGNED_SHORT, glyphList.m_pList); 
      

  3.   

    void CText::Draw()
    {
    CFont newfont,*oldfont;
    newfont.CreateFont(
    -12,0,0,0,400,
    m_bItalic,false,false,
    DEFAULT_CHARSET,
    OUT_DEFAULT_PRECIS,
    CLIP_DEFAULT_PRECIS,
    DEFAULT_QUALITY,
    DEFAULT_PITCH,m_FontName); oldfont=(CFont*)SelectObject(wglGetCurrentDC(),newfont);
    glPushMatrix(); float red,green,blue;
    red=GetRValue(m_FillColor1);
    green=GetGValue(m_FillColor1);
    blue=GetBValue(m_FillColor1);
    glColor3f(red/255,green/255,blue/255); glTranslatef(m_point.x,m_point.y,0);
    glScalef(m_nFontSize,-m_nFontSize,1);
    DrawString1((unsigned char*)(LPCTSTR)m_Name);
    glRasterPos2f(0,0);
    DrawString2((unsigned char*)(LPCTSTR)m_Name);
    glPopMatrix(); SelectObject(wglGetCurrentDC(),oldfont);
    }
    void CText::DrawString1(unsigned char* str)
    {
    HDC hDC=wglGetCurrentDC();
    DWORD dwChar;
    int ListNum;
    glPushMatrix();
    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);
    GLYPHMETRICSFLOAT pgmf;
    wglUseFontOutlines(hDC,dwChar,1,ListNum,0,0,WGL_FONT_LINES,&pgmf);
    glLineWidth(1);
    glLineStipple(1,0xffff);
    glCallList(ListNum);
    glDeleteLists(ListNum,1);
    }
    glPopMatrix();
    }
    void CText::DrawString2(unsigned char* str)
    {
    HDC hDC=wglGetCurrentDC();
    DWORD dwChar;
    int ListNum;
    glPushMatrix();
    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);
    GLYPHMETRICSFLOAT pgmf;
    wglUseFontOutlines(hDC,dwChar,1,ListNum,0,0,WGL_FONT_POLYGONS,&pgmf);
    glCallList(ListNum);
    glDeleteLists(ListNum,1);
    }
    glPopMatrix();
    }
    这样画出来的字只有斜体效果,并且大小无法指定,我是用glScale更改的大小。