Skip to content

stbtt_GetGlyphSDF() yoff return negative values. #1700

Closed

Description

@Intervel

why does yoff return negative values?

f32 scale = stbtt_ScaleForMappingEmToPixels(&fontInfo, 64.0f);
i32 padding = 5;
u8 onedgeValue = 180;
f32 pixelDistScale = 180 / 5.0;

i32 glyphIndex = stbtt_FindGlyphIndex(&fontInfo, codepoint);

i32 advance{0}; i32 lsb{0};
stbtt_GetGlyphHMetrics(&fontInfo, glyphIndex, &advance, &lsb);

i32 width{0}; i32 height{0}; i32 xoff{0}; i32 yoff{0};
u8* sdf = stbtt_GetGlyphSDF(&fontInfo, scale, glyphIndex, padding, onedgeValue, pixelDistScale, &width, &height, &xoff, &yoff);
-40
-53
-40
-54
-40
-53
-52
-52
-53
-53
-40
-40
-40
-40
-40
-40
-40

this is how i store it into json.

json glyph;
glyph["width"] = width;
glyph["height"] = height;
glyph["xadvance"] = (advance * scale);
glyph["xoff"] = xoff;
glyph["yoff"] = yoff;
glyph["texcoord"] = { texTop, texRight, texBottom, texLeft };

somehow, because its negative, it place it above. is this a bug?
tried to open this json file, yoff is mostly negative. be aware im using the SDF function one. stbtt_GetGlyphSDF()
Roboto-Regular.json

this is how i put it on screen

//f32 posY   = current.y - (mFont->getCharacters()[currentUnicode].size.y - mFont->getCharacters()[currentUnicode].offset.y) * text.fontSize;
f32 posY   = current.y + (mFont->getCharacters()[currentUnicode].offset.y) * text.fontSize;

// yoff = mFont->getCharacters()[currentUnicode].offset.y)

4
5
Roboto-Regular

Activity

  1. blackedout01 commented on Oct 7, 2024

    @blackedout01
    Contributor

    I think that's because yoff is relative to the baseline of the character. It looks like your current.y is the top of where you are drawing, but it should be the baseline.

  2. Repository owner locked and limited conversation to collaborators on Oct 7, 2024
  3. converted this issue into a discussion #1701 on Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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