如何在 PyOpenGL 中更改位图字符的字体大小? [英] How to change font size of bitmap characters in PyOpenGL?

查看:114
本文介绍了如何在 PyOpenGL 中更改位图字符的字体大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am making a game in PyOpenGL and I am using some text overlapping. How can I change the font size of the fonts included in OpenGL.GLUT?

这就是我现在所拥有的:

This is what I have now:

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)

推荐答案

遗憾的是你不能.

glutBitmapCharacter 使用glBitmap以 1:1 的像素比将位图光栅化(和blit")到帧缓冲区.因此位图无法缩放,位置由 glWindowPos 分别为 glRasterPos.

如果要绘制不同大小的文本,则必须选择不同的字体,请参阅 glutBitmapCharacter.

If you want to draw a text with a different size then you've to choose a different font, s ee glutBitmapCharacter.

当您使用 glutStrokeCharacter 时,文本由线图元绘制.文本的粗细可以通过glLineWidth<设置/代码>.文本的位置和大小可以取决于当前模型视图矩阵和投影矩阵.所以文本的位置可以通过glTranslate 并且可以通过 glScale.文本甚至可以通过 glRotate<旋转/code>.

When you use glutStrokeCharacter then the text is drawn by line primitives. THe thickness of the text can be set by glLineWidth. The position and size of the text can depends on the current model view matrix a nd projection matrix. So the position of the text can be set by glTranslate and the size can be changed by glScale. The text can even be rotated by 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.

See also freeglut - 14. Font Rendering Functions for the use of glutBitmapString respectively glutStrokeString.

这篇关于如何在 PyOpenGL 中更改位图字符的字体大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆