Posted By

n3x on 05/30/07


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


Cross-platform text rendering in pygame with AGG

 / Published in: Python

A quick first test case in which I use aggdraw for rendering text to a pygame Surface. Pygame's font-rendering doesn't work properly cross-platform, and this looks promising. I'll need to integrate the AGG canvas more tightly with the pygame Surface, but I think it'll work out.

  1. import aggdraw as ag
  2. import pygame as pg
  4. class TextPainter(Painter):
  5. def __init__(self, text, *args, **kwds):
  6. Painter.__init__(self, *args, **kwds)
  7. self.text = text
  8. self.canvas = ag.Draw("RGB", (self.width, self.height),
  9. ColourScheme.background)
  10. self.font = ag.Font(ColourScheme.text,
  11. os.path.join("..", "gfx", "slkscr.ttf"), 8)
  12. self.canvas.text((0, 0), self.text, self.font)
  13. = pg.image.fromstring(self.canvas.tostring(),
  14. (self.width, self.height), "RGB")
  15. self.window = Window()
  16. self.window.addPainter(self)
  18. def paint(self):
  19. self.window.blit(, (self.xPos, self.yPos))

Report this snippet  

You need to login to post a comment.