libgdx中的距离字段字体

libgdx中的距离字段字体,libgdx,Libgdx,我正在尝试渲染平滑的可缩放位图字体。在使用距离字段字体检查这一项后 我所做的正是关于距离场字体中提到的。但是我不能让它工作。字体呈现模糊 下面是我用来生成这个输出的代码 公共类FontRenderTest实现ApplicationListener{ 私有纹理; 私人SpriteBatch SpriteBatch; 专用位图字体; @凌驾 公共void create(){ spriteBatch=新spriteBatch(); 纹理纹理=新纹理(Gdx.files.internal(“ralwa

我正在尝试渲染平滑的可缩放位图字体。在使用距离字段字体检查这一项后

我所做的正是关于距离场字体中提到的。但是我不能让它工作。字体呈现模糊

下面是我用来生成这个输出的代码

公共类FontRenderTest实现ApplicationListener{
私有纹理;
私人SpriteBatch SpriteBatch;
专用位图字体;
@凌驾
公共void create(){
spriteBatch=新spriteBatch();
纹理纹理=新纹理(Gdx.files.internal(“ralway.png”),true);//true启用mipmap
texture.setFilter(TextureFilter.MipmapLinearSet,TextureFilter.Linear);//最近的mipmap图像中的线性过滤
font=新位图字体(Gdx.files.internal(“ralway.fnt”),新纹理区域(纹理),false);
}
@凌驾
公共无效呈现(){
glClearColor(0,0,0,1);
Gdx.gl.glClear(GL10.gl\u颜色\u缓冲\u位);
spriteBatch.begin();
绘制(spriteBatch,“这是朦胧!!”,100150);
spriteBatch.end();
}
}

我不确定我是否正确理解距离字段字体的功能。如果有人能解释如何使字体平滑

我认为它需要一个着色器,如果我没有记错的话,着色器需要GL20。正如wiki中所说,您需要.frag和.vert文件。我在这个Libgdx测试的帮助下修改了您的代码:

它看起来像这样,平滑度不同。

公共类FontRenderTest实现ApplicationListener{
私有纹理;
私人SpriteBatch SpriteBatch;
专用位图字体;
私有距离字段着色器距离字段着色器;
私有静态类DistanceFieldShader扩展ShaderProgramm{
公共距离字段着色器(){
//vert和frag文件是从中复制的http://git.io/yK63lQ (垂直)和http://git.io/hAcw9Q (frag)
super(Gdx.files.internal(“data/shaders/distancefield.vert”)、Gdx.files.internal(“data/shaders/distancefield.frag”);
如果(!isCompiled()){
抛出新的运行时异常(“着色器编译失败:\n”+getLog());
}                                                                                                                   
}                                                                                                                       
/**@param平滑0和1之间的值*/
公共无效设置平滑(浮点平滑){
浮点增量=0.5f*数学钳位(平滑,0,1);
setUniformf(“u_较低”,0.5f-三角洲);
setUniformf(“u_上”,0.5f+三角洲);
}                                                                                                                       
}                                                                                                                           
@凌驾
public void create(){
spriteBatch=新spriteBatch();
纹理纹理=新纹理(Gdx.files.internal(“hiero.png”),true);//true启用mipmap
texture.setFilter(TextureFilter.MipmapLinearSet,TextureFilter.Linear);//最近的mipmap图像中的线性过滤
font=新位图字体(Gdx.files.internal(“hiero.fnt”),新纹理区域(纹理),false);
distanceFieldShader=新的distanceFieldShader();
}
@凌驾
public void render(){
glClearColor(0,0,0,1);
Gdx.gl.glClear(GL20.gl\u颜色\u缓冲\u位);
spriteBatch.begin();
spriteBatch.setShader(distanceFieldShader);
绘制(spriteBatch,“这很尖锐!!”,100,120);
distanceFieldShader.setSmoothing(0f);
spriteBatch.setShader(distanceFieldShader);
绘制(spriteBatch,“这是朦胧!!”,100150);
distanceFieldShader.setSmoothing(1f);