Skip to content

[rtext] Incorrect rendering of pixel font #5678

@Vanglant

Description

@Vanglant

Issue description

Hello! I'm using the m5x7 pixel font(https://managore.itch.io/m5x7) in my game, with a 480x270 render target (point texture filter) that is rendered then to the screen (960,540), it currently looks like this (using point texture filter as well):
Image

I noticed that it is rendering fine in Foster framework and they are also using stb_truetype, but instead of
stbtt_ScaleForPixelHeight

float scaleFactor = stbtt_ScaleForPixelHeight(&fontInfo, (float)fontSize);

they are using:
stbtt_ScaleForMappingEmToPixels https://github.com/FosterFramework/Foster/blob/0b814e1ee312d216008c1fd2291f0e0b12295c91/Framework/Internal/ThirdParty/StbTrueType.cs#L48

Compiled latest raylib with this change and looks like the output is correct now:
Image

I'm not sure if this is a breaking change, tried the text_font_filters example with the change and seems to be ok aswell, but not sure yet, currently going through the stb_truetype docs to find out more info https://github.com/nothings/stb/blob/28d546d5eb77d4585506a20480f4de2e706dff4c/stb_truetype.h#L766

Also this issue might be relevant: nothings/stb#689

Found similar issues: https://www.reddit.com/r/raylib/comments/1g0pwr5/pixel_font_blurriness_with_specific_fonts/
https://www.reddit.com/r/raylib/comments/1g0cbny/pixel_font_distortion/

Environment

Windows 11

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions