[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] Ugly fonts (yes, I use AA)



My app is based on three classes, one widget class, one scene class
(something like a frame, or window in GUI world, and app class which
manages all the details. Now, the problem is that when widget class
renders fonts they look really crappy. Turning AA on/off does make a
difference in their appearance, but even with AA switched on, the
result is rather bad.

The thing that puzzles me the most is the fact that when I render the
same font on my display surface, without using widget->scene->app
classes I get perfectly fine looking fonts :(. What could I have done
wrong so that my fonts get messed up?

My design is as follows: widget uses its own Surface to do the
drawing, and renders text to that surface. Then, when update is needed
scene class takes widgets Surface and blits that with it's own
Surface, and then scene Surface finally gets blitted to main display
surface.

Does anyone have any idea what could possibly go wrong during this
process? If needed, I'll attach my code later...

Here is the code to the widget class, because I suspect that's where
my problem lies:

--- cut here ---
class Viewport:
   def __init__(self, parent, size, pos, bgimage, margin, font_path,
font_size):
       parent.Bind(self)

       self.size = size
       self.pos = pyg.Rect((pos, size))
       self.font_size = font_size

       # main drawing surface
       self.canvas = pyg.image.load(bgimage).convert()
       self.crect = self.canvas.get_rect()

       self.font = pyg.font.Font(font_path, font_size)

       self.items = []
       self.nitems = 0
       self.ritems = pyg.Rect((self.crect.x + margin,
                               self.crect.y + margin,
                               self.crect.w - margin,
                               self.crect.h - margin))
       self.visible_items = self.ritems.h / font_size
       self.top_item = 0
       self.bottom_item = 0

   def update(self):
       text_row = 0
       for item in self.items:
           item_text = self.font.render(item, 0, (249, 249, 249))
           self.canvas.blit(item_text, self.ritems.move(0, text_row))
           text_row += self.font_size + 1

   def add(self, item):
       self.items.append(item)
       self.nitems += 1
       self.bottom_item += 1
--- cut here ---

Thanks guys...

--
Karlo Lozovina -- Mosor
"Parce mihi domine quia Dalmata sum."