我需要在窗口中显示文本,我找到了这样的解决方案,但是它什么也画不出来
def drawText(x, y, text):
position = (x, y, 0)
font = pygame.font.SysFont('arial', 64)
textSurface = font.render(text, True, (255,255,66,255), (0,66,0,255))
textData = pygame.image.tostring(textSurface, "RGBA", True)
glRasterPos3d(*position)
glDrawPixels(textSurface.get_width(), textSurface.get_height(), GL_RGBA, GL_UNSIGNED_BYTE, textData)
有没有办法在pygame窗口中只显示文本?
1条答案
按热度按时间pdtvr36n1#
使用
glWindowPos
而不是glRasterPos
。当glRasterPos
的坐标由当前模型视图和投影矩阵转换时,glWindowPos
直接更新当前栅格位置的x和y坐标。另请参阅PyGame和OpenGL即时模式(传统OpenGL)-文本
最小示例:
对于具有透明背景的文本,您需要使用
convert_alpha()
将文本表面转换为每像素格式:此外,您必须启用Blending:
最小示例:
replit.com/@Rabbid76/pygame-opengl-text