Distance field font in libgdx -



Distance field font in libgdx -

i'm trying rendering smooth scalable bitmap fonts. after checking question 1 of answers mentioned using distance field fonts.

i'm doing mentioned in libgdx wiki article distance filed fonts. can't working. fonts rendered hazy.

here's code used generate output

class="lang-java prettyprint-override">public class fontrendertest implements applicationlistener { private texture texture; private spritebatch spritebatch; private bitmapfont font; @override public void create() { spritebatch = new spritebatch(); texture texture = new texture(gdx.files.internal("raleway.png"), true); // true enables mipmaps texture.setfilter(texturefilter.mipmaplinearnearest, texturefilter.linear); // linear filtering in nearest mipmap image font = new bitmapfont(gdx.files.internal("raleway.fnt"), new textureregion(texture), false); } @override public void render() { gdx.gl.glclearcolor(0, 0, 0, 1); gdx.gl.glclear(gl10.gl_color_buffer_bit); spritebatch.begin(); font.draw(spritebatch, "this hazy !!", 100, 150); spritebatch.end(); } }

i'm not sure if understand function of distance field font. if explain how render font smooth.

i think needs shader , if recall right shaders require gl20. said in wiki need .frag , .vert files. modified code help libgdx test: http://git.io/-yamng .

it looks different smoothing.

class="lang-java prettyprint-override">public class fontrendertest implements applicationlistener { private texture texture; private spritebatch spritebatch; private bitmapfont font; private distancefieldshader distancefieldshader; private static class distancefieldshader extends shaderprogram { public distancefieldshader () { // vert , frag files copied http://git.io/yk63lq (vert) , http://git.io/hacw9q (the frag) super(gdx.files.internal("data/shaders/distancefield.vert"), gdx.files.internal("data/shaders/distancefield.frag")); if (!iscompiled()) { throw new runtimeexception("shader compilation failed:\n" + getlog()); } } /** @param smoothing value between 0 , 1 */ public void setsmoothing (float smoothing) { float delta = 0.5f * mathutils.clamp(smoothing, 0, 1); setuniformf("u_lower", 0.5f - delta); setuniformf("u_upper", 0.5f + delta); } } @override public void create() { spritebatch = new spritebatch(); texture texture = new texture(gdx.files.internal("hiero.png"), true); // true enables mipmaps texture.setfilter(texturefilter.mipmaplinearnearest, texturefilter.linear); // linear filtering in nearest mipmap image font = new bitmapfont(gdx.files.internal("hiero.fnt"), new textureregion(texture), false); distancefieldshader = new distancefieldshader(); } @override public void render() { gdx.gl.glclearcolor(0, 0, 0, 1); gdx.gl.glclear(gl20.gl_color_buffer_bit); spritebatch.begin(); spritebatch.setshader(distancefieldshader); font.draw(spritebatch, "this pretty sharp !!", 100, 120); distancefieldshader.setsmoothing(0f); spritebatch.setshader(distancefieldshader); font.draw(spritebatch, "this hazy !!", 100, 150); distancefieldshader.setsmoothing(1f); spritebatch.setshader(distancefieldshader); font.draw(spritebatch, "this pretty smooth !!", 100, 180); distancefieldshader.setsmoothing(1/2f); spritebatch.end(); }

libgdx

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -