The wglUseFontBitmaps() function creates a set of bitmap display lists based on the glyphs in the currently selected font in the current DC for use in the current OpenGL RC. It basically creates a series of sequential display lists which can be executed using the function glCallLists. The function takes care of aligning the raster positions of subsequent bitmaps once we specify the raster position for the first bitmap. We use the glRasterPos function to set the current raster position, where the bitmapped text would start appearing.
The glRasterPos function works exactly the same way as glVertex function, the only difference being that the position is being transformed and not the object. Thus when we use wglUseFontBitmaps to generate display lists and then call them, the resulting text is displayed, starting at the current raster position, and the bitmaps are copied to the raster buffer, giving the effect of always having the text positioned in the xy plane of the screen.
Thus we would use wglUseFontBitmaps when we need the text to be visible to the user and that the size of the text relative to its distance from the viewpoint doesn't matter.
The wglUseFontOutlines function creates a set of 3D polygon or line based primitive display lists, based on the glyphs in the currently selected TrueType font in the current DC for use in the current OpenGL RC. Stroke and Raster fonts are not supported. These objects can then be used to draw 3D characters. This function also has additional arguments that control the extrusion of the 3D characters in the +Z direction, the deviation of the generated primitive vertices from the design outline of the font, whether to generated filled polygons or a wireframe primitives and an array of structures to hold the metrics of each of the generated characters.
1,在CCY457OpenGLView类中加入下述变量:
BOOL m_b3DText, m_b2DText;
CCY457OpenGLView::CCY457OpenGLView()
void CCY457OpenGLView::OnText2dtext()
InvalidateRect(NULL,FALSE);
void CCY457OpenGLView::OnText3dtext()
InvalidateRect(NULL,FALSE);
void CCY457OpenGLView::OnUpdateText2dtext(CCmdUI* pCmdUI)
pCmdUI->SetRadio(m_b2DText);
void CCY457OpenGLView::OnUpdateText3dtext(CCmdUI* pCmdUI)
pCmdUI->SetRadio(m_b3DText);
void CCY457OpenGLView::Create3DTextLists()
GLYPHMETRICSFLOAT agmf[256];
m_font.CreateFont( -12, // Height Of Font
0, // Angle Of Escapement
ANSI_CHARSET, // Character Set Identifier
OUT_TT_PRECIS, // Output Precision
CLIP_DEFAULT_PRECIS, // Clipping Precision
ANTIALIASED_QUALITY, // Output Quality
FF_DONTCARE|DEFAULT_PITCH, // Family And Pitch
CFont* m_pOldFont = m_pDC->SelectObject(&m_font);
// create display lists for glyphs 0 through 255 with 0.1 extrusion
// and default deviation. The display list numbering starts at 1000
// (it could be any number)
m_3DTextList = glGenLists(256);
wglUseFontOutlines(m_pDC->GetSafeHdc(), 0, 255, m_3DTextList, 0.0f, 0.5f,WGL_FONT_POLYGONS, agmf);
m_pDC->SelectObject(m_pOldFont);
void CCY457OpenGLView::Create2DTextLists()
m_font.CreateFont( -24, // Height Of Font
0, // Angle Of Escapement
FW_NORMAL, // Font Weight
ANSI_CHARSET, // Character Set Identifier
OUT_TT_PRECIS, // Output Precision
CLIP_DEFAULT_PRECIS, // Clipping Precision
DEFAULT_QUALITY, // Output Quality
FF_DONTCARE|DEFAULT_PITCH, // Family And Pitch
CFont* m_pOldFont = m_pDC->SelectObject(&m_font);
// create display lists for glyphs 0 through 255 with 0.1 extrusion
// and default deviation. The display list numbering starts at 1000
// (it could be any number)
m_2DTextList = glGenLists(256);
wglUseFontBitmaps(m_pDC->GetSafeHdc(), 0, 255, m_2DTextList);
m_pDC->SelectObject(m_pOldFont);
4, InitializeOpenGL函数中调用上述两个函数:
BOOL CCY457OpenGLView::InitializeOpenGL()
//Get a DC for the Client Area
m_pDC = new CClientDC(this);
MessageBox("Error Obtaining DC");
//Failure to set the pixel format
//Create Rendering Context
m_hRC = ::wglCreateContext (m_pDC->GetSafeHdc ());
//Failure to Create Rendering Context
MessageBox("Error Creating RC");
if(::wglMakeCurrent (m_pDC->GetSafeHdc (), m_hRC)==FALSE)
MessageBox("Error making RC Current");
//Specify Black as the clear color
::glClearColor(0.0f,0.0f,0.0f,0.0f);
//Specify the back of the buffer as clear depth
::glEnable(GL_DEPTH_TEST);
//Create Font Display Lists
void CCY457OpenGLView::RenderScene ()
glTranslatef(-1.0f,0.0f,-5.0f);
glRotatef(-10.0,1.0f,0.0f,0.0f);
glRotatef(-10.0,0.0f,1.0f,0.0f);
// Position The Text On The Screen
glColor3f(1.0f,1.0f,0.0f);
glListBase(m_2DTextList);
glCallLists(6, GL_UNSIGNED_BYTE ,"OpenGL");
glListBase(m_3DTextList);
glCallLists(6, GL_UNSIGNED_BYTE ,"OpenGL");
本文转自Phinecos(洞庭散人)博客园博客,原文链接:http://www.cnblogs.com/phinecos/archive/2008/11/06/1328250.html,如需转载请自行联系原作者