1

I'm developing a simple game using pygame library, but when I started to draw text (antialiasing is on) it has turned to be a little bit differ from my Photoshop concept. Font looks too sharp for my sight. Some letters are too thin, others are too thick. Some lower, some higher. Here is an example (digits look really unproportional).

Photoshop:

Photoshop fonts

My game:

Actual fonts

Important to mention, that in photoshop there is an option sharp which made my text look just like it is in my game now (pic. 2). So I switched it to smooth and result is on the first picture.

So can I fix this sharp font somehow and make it look smoother? Maybe better to use images for static text? Or should I just deal with it?

Tikhon Belousko
  • 767
  • 1
  • 9
  • 26
  • Just to be clear, are these the exact same fonts? Because the 9 and 8 appears to be different in the two. – Torxed Nov 20 '13 at 09:49
  • Photoshop likely uses proprietary font-rendering code similar to the hinting used with Adobe's Type1 fonts and similar to the ClearType rendering technology Microsoft ame up with for rendering TrueType fonts on LCD screens -- so I suspect you're stuck with what Pygame provides or generating your own images of static text. – martineau Nov 20 '13 at 09:50
  • @Torxed: Yeah, those 0's look really different. ;-) – martineau Nov 20 '13 at 09:51
  • Also this has more to do with opengl than Pygame. You see, you need to instruct the underlaying engine to actually smooth certain things out, anti-aliasing is just one of the many ways to smooth lines, a great example is given here: http://stackoverflow.com/questions/2747784/pyglet-opengl-drawing-anti-aliasing – Torxed Nov 20 '13 at 09:51
  • @martineau Well spotted, ment 8's of-course ;) – Torxed Nov 20 '13 at 09:52
  • Anti-aliasing the rendering of text is not the same thing as using hinting in its rendering. – martineau Nov 20 '13 at 09:54
  • @Torxed Yes, it is absolutely the same font from the same ttf. It's Helvetica Neue Light, by the way. I don't want to use opengl because it makes code look harder to read and it is harder for usage. I need something more "light" and pygame seemed to be a right choice... – Tikhon Belousko Nov 20 '13 at 13:00
  • 1
    @DaZzz I don't want to be the one to tell you this, but you have to dig deep in order to get more advance features (perhaps this time as well). Graphics is made "easy" but only to a certain degree with Pygame/wxPython/PyGUI etc (see a full list here: https://wiki.python.org/moin/GuiProgramming). I use Pyglet myself because i've realized that once you dig down into graphics you're better off just doing it as natively as possible both for speed but also for understanding what's happening because every now and then you'll bump into issues like this and you have no clue how to solve them otherwise – Torxed Nov 21 '13 at 09:16
  • @DaZzz have you found a solution? I have **exactly** the same question with some Python code : I would like to use Helvetica and have smooth letters like in Photoshop ! – Basj Dec 12 '13 at 20:25
  • @Basj to be honest I haven't found anything and it seems like there is no good solution. I've decided to leave it as it is. Also, if you will find something don't forget to post it here! – Tikhon Belousko Dec 13 '13 at 21:37
  • I think this feature is called "font anti-aliasing"... We have to look for that ! – Basj Dec 13 '13 at 22:08

1 Answers1

1

I recommend to use the pygame.freetype module to get better results.

Minimal example:

import pygame
import pygame.freetype

pygame.init()
window = pygame.display.set_mode((500, 150))
clock = pygame.time.Clock()
ft_font = pygame.freetype.SysFont('Sans', 50)

run = True
while run:
    clock.tick(60)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False

    window.fill((255, 255, 255))
    text_str = 'Player 1    9:8    Player 2'
    text_rect = ft_font.get_rect(text_str)
    text_rect.center = window.get_rect().center
    ft_font.render_to(window, text_rect.topleft, text_str, (100, 200, 255))
    pygame.display.flip()

pygame.quit()
exit()
Rabbid76
  • 202,892
  • 27
  • 131
  • 174