使用像Libgdx:https://github.com/libgdx/libgdx/wiki/Distance-field-fonts中解释的那样的距离字段字体在android上有很好的效果。我正在使用提供的示例着色器。
但是当我在iOS上运行相同的程序时,文本到处都是白色的(见下图)。是iOS不支持距离字段,还是需要添加/更改其他内容才能使其工作?

着色代码font.vert:
uniform mat4 u_projTrans;
attribute vec4 a_position;
attribute vec2 a_texCoord0;
attribute vec4 a_color;
varying vec4 v_color;
varying vec2 v_texCoord;
void main() {
gl_Position = u_projTrans * a_position;
v_texCoord = a_texCoord0;
v_color = a_color;
}font.frag:
#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2D u_texture;
varying vec4 v_color;
varying vec2 v_texCoord;
const float smoothing = 1.0/16.0;
void main() {
float distance = texture2D(u_texture, v_texCoord).a;
float alpha = smoothstep(0.5 - smoothing, 0.5 + smoothing, distance);
gl_FragColor = vec4(v_color.rgb, alpha);
}像这样加载字体:
BitmapFont bf = new BitmapFont(Gdx.files.internal("fonts/mont-b.fnt"));
bf.getRegion().getTexture().setFilter(TextureFilter.MipMapLinearNearest, TextureFilter.Linear);着色器:
fontShader = new ShaderProgram(Gdx.files.internal("shader/font.vert"), Gdx.files.internal("shader/font.frag"));发布于 2015-01-12 14:08:53
我认为问题可能在于您的字体纹理上没有启用mip映射,因为您只是使用简单的BitmapFont构造函数而没有TextureRegion参数,所以它加载纹理时假定没有mip映射。
您必须创建一个支持这样的mip映射的纹理,如libgdx所示:
Texture texture = new Texture(Gdx.files.internal("yourFont.png"), true); //true to enable mip maps
texture.setFilter(TextureFilter.MipMapLinearNearest, TextureFilter.Linear);然后可以使用mip映射纹理加载BitmapFont,这样BitmapFont就不会在没有mip映射的情况下创建自己的纹理:
BitmapFont bf = new BitmapFont(Gdx.files.internal("fonts/mont-b.fnt"), new TextureRegion(texture));发布于 2018-04-22 17:16:59
你的密码没问题。但是,默认情况下,iOS对所有图像使用预乘alpha。因此,您正在使用的图像被转换为预乘alpha格式,而不是您提供的相同格式。
不确定确切的位置,但您需要禁用图像的预乘alpha,“方框”就会消失。
不,你的问题与mipmapping无关。
https://stackoverflow.com/questions/27892283
复制相似问题