在使用OpenGL位图字体时,是否可以获取字符的宽度?

1 投票
1 回答
724 浏览
提问于 2025-04-15 20:03

我正在尝试在我的OpenGL应用程序中对位图字体文本进行对齐,但我找不到获取每个字符宽度的方法。这是我的renderText函数:

def renderText( self, text, fontFace, position ):
    ..... (omitted code to make post shorter)
    glRasterPos2i( position[0], self.windowSize[1] - position[1] )
    glPushAttrib( GL_LIST_BIT )
    glListBase( self.fonts[ fontFace ] - 32 )
    glCallLists( text )
    glPopAttrib()
    ......

我创建了位图字体,并使用glGenList来存储它。

    self.fonts[ fontFace ] = glGenLists( 96 )
    font = win32ui.CreateFont( fontProperties )
    font = hDisplayContext.SelectObject( font )
    wglUseFontBitmaps( displayContext, 32, 96, self.fonts[ fontFace ] )

有没有人知道是否可以获取字符的宽度,或者至少获取最终渲染文本的总宽度?

1 个回答

1

glutBitmapWidthglutBitmapLength 是用来获取位图字符或字符串的宽度和长度的函数。

Python 规范:

glutBitmapWidth(font, character) -> None
glutBitmapLength(font, string) -> None

撰写回答