Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Proper scaling and positioning with freetype #108

Closed
vaheqelyan opened this issue Jul 12, 2020 · 4 comments
Closed

Question: Proper scaling and positioning with freetype #108

vaheqelyan opened this issue Jul 12, 2020 · 4 comments

Comments

@vaheqelyan
Copy link

i know this is not the right place to ask this question, but I need help.
this was the command I ended up using.

./msdfgen msdf -font Lato-Regular.ttf '72' -size 96 96 -pxrange 12 -autoframe -o ../basic-gl/H.png

i used FreeType 2 to provide the kerning, size, etc.

Here is my result (Lato Font, 40px)

image

I highlighted the characters

image

Can you tell me how I can scale bitmaps or get the right metrics for rendering ? I mean, the character "H" should be a little wider
How can I maintain bitmap data along with generated textures

Here is a comparison of text in a web browser
image

Here's what my fragment shader looks like

#version 430 core
out vec4 color;

in vec2 uv;
in float layer_get;

layout (binding=0) uniform sampler2DArray textureArray;

float median(float r, float g, float b) {
    return max(min(r, g), min(max(r, g), b));
}

void main()
{
      vec3 flipped_texCoords = vec3(uv, layer_get);
      vec2 pos = flipped_texCoords.xy;
      vec3 dis = texture(textureArray, flipped_texCoords).rgb;
      ivec2 sz = textureSize(textureArray, 0).xy;
      float dx = dFdx(pos.x) * sz.x; 
      float dy = dFdy(pos.y) * sz.y;
      float sigDist = median(dis.r, dis.g, dis.b);
      float w = fwidth(sigDist);
      float opacity = smoothstep(0.5 - w, 0.5 + w, sigDist);
      color = mix(vec4(1.0,0.0,1.0,1.0), vec4(0.0,0.0,0.0,1.0), opacity);
}

This is the only progress I have made so far.
./msdfgen msdf -font Lato-Regular.ttf '72' -size 96 96 -pxrange 12 -autoframe -scale 5 -o ../basic-gl/H.png
image

btw thank you for your software !

@Chlumsky
Copy link
Owner

First of all, don't use -autoframe. I even added a disclaimer on the front page but everyone still uses it and then wonders how to typeset with each letter scaled differently and centered (losing any sort of positioning). Then you gotta set the translation and scale that you compute with some sophisticated logic.

I don't know what exactly you're trying to do but I think you might want to take a look at https://github.com/Chlumsky/msdf-atlas-gen and see if it maybe solves the exact same problem you're working on.

@vaheqelyan
Copy link
Author

thank you for your quick response

First of all, don't use -autoframe

yeah i know, i used this command earlier

./msdfgen msdf -font Lato-Regular.ttf '72' -size 96 96 -pxrange 12 -scale 2 -translate 3 20 -o ../basic-gl/H.png

but i practically had the same problem as now

I don't know what exactly you're trying to do but I think you might want to take a look at https://github.com/Chlumsky/msdf-atlas-gen and see if it maybe solves the exact same problem you're working on.

i store each image in a texture array, i don't use texture atlas.
can this cause a problem ?

@Chlumsky
Copy link
Owner

You can use a texture array, that's not a problem but you seem to have a hard time getting the positioning right, so I was thinking that you may want to use something that already has this solved.

@vaheqelyan
Copy link
Author

ok i will try msdf-atlas-gen. I'll let you know. thank's.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants