|
|
发表于 2006-2-26 14:37:00
|
显示全部楼层
Re:bitmapfont 问题,多谢
GLuint line_left, line_right; //要输出文字的区域,值由你设定。
GLuint text_width; //文本的宽度,计算方法后述
GLuint line_width = line_right - line_left;
GLuint x = ( line_width - text_width ) / 2 + line_left;
glRasterPos2ui( x, y ); // y由你设定
//输出字符串
--------------------------------------------
获得文本宽度的方法:(WIN32 API)
BOOL GetTextExtentPoint32(
HDC hdc, // handle to DC
LPCTSTR lpString, // text string
int cbString, // characters in string
LPSIZE lpSize // string size
);
示例:
HDC hdc = wglGetCurrentDC( );
LPCTSTR str = _T("你要输出的字符串");
int len = _tcslen( str );
SIZE temp; // 接受逻辑尺寸
if( GetTextExtentPoint32( hdc, str, len, &temp ) )
{
text_width = temp.x;
} |
|