如何在PyOpenGL中更改位图字符的字体大小?

诺亚

我在PyOpenGL中制作游戏,并且使用了一些重叠的文本。如何更改其中包含的字体的字体大小OpenGL.GLUT

这就是我现在所拥有的:

def blit_text(x,y,font,text,r,g,b):
    blending = False 
    if glIsEnabled(GL_BLEND):
        blending = True
    glColor3f(r,g,b)
    glWindowPos2f(x,y)
    for ch in text:
        glutBitmapCharacter(font,ctypes.c_int(ord(ch)))
    if not blending:
        glDisable(GL_BLEND)

blit_text(displayCenter[0] - 5,displayCenter[1] - 5,GLUT_BITMAP_TIMES_ROMAN_24,"*",0,1,0)
拉比德76

可悲的是你不能。

glutBitmapCharacter用于glBitmap以1:1像素比例将位图栅格化(并“填充”)到帧缓冲区。因此,位图无法缩放,位置glWindowPos分别由设置glRasterPos

如果要绘制不同大小的文本,则必须选择其他字体s ee glutBitmapCharacter

使用时glutStrokeCharacter,文本将由线图元绘制。文字的粗细可以通过设置glLineWidth文本的位置和大小可以取决于当前的模型视图矩阵和投影矩阵。因此,可以通过设置文本的位置,glTranslate并可以通过更改大小glScale文本甚至可以旋转glRotate

例如:

def blit_text(x,y,font,text,r,g,b):

    glColor3f(r,g,b)
    glLineWidth(5)
    glTranslatef(x, y, 0)
    glScalef(1, 1, 1)
    for ch in text:
        glutStrokeCharacter(font,ctypes.c_int(ord(ch)))

glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(0, windowWidth, 0, windowHeight, -1, 1)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()

blit_text(10, 10, GLUT_STROKE_ROMAN, "**", 0, 1, 0)

又见freeglut - 14字体渲染功能的使用的glutBitmapString分别glutStrokeString

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章