如何更改 PyOpenGL 中位图字符的字体大小?
How to change font size of bitmap characters in 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)
遗憾的是你不能。
glutBitmapCharacter
uses glBitmap
to raster (and "blit") the bitmap to the framebuffer, in 1:1 pixel ratio. Thus the bitmap can't be scaled and the position is set by glWindowPos
respectively glRasterPos
.
如果要绘制不同大小的文本,则必须选择不同的字体,请参阅 glutBitmapCharacter
。
当您使用 glutStrokeCharacter
时,文本由线基元绘制。文字的粗细可以通过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. Font Rendering Functions 分别了解 glutBitmapString
的用法 glutStrokeString
。
我正在 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)
遗憾的是你不能。
glutBitmapCharacter
uses glBitmap
to raster (and "blit") the bitmap to the framebuffer, in 1:1 pixel ratio. Thus the bitmap can't be scaled and the position is set by glWindowPos
respectively glRasterPos
.
如果要绘制不同大小的文本,则必须选择不同的字体,请参阅 glutBitmapCharacter
。
当您使用 glutStrokeCharacter
时,文本由线基元绘制。文字的粗细可以通过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. Font Rendering Functions 分别了解 glutBitmapString
的用法 glutStrokeString
。