【发布时间】:2015-01-31 17:09:36
【问题描述】:
作为着色器的新手,当我成功(ish)设法让 DistanceFieldFont 着色器工作时,我很高兴。 当放大时,它似乎可以很好地使文本看起来清晰......
...但是缩小后看起来很可怕:
左边的文字是一个普通的LibGDX标签,用于比较。
制作材料的代码是;
Texture texture = generateTexture(contents); //function generate text-texture from supplied letters
texture.setFilter(TextureFilter.MipMapLinearLinear, TextureFilter.Linear);//Isnt this supposed to ensure smooth zoomout?
Material mat = new Material(TextureAttribute.createDiffuse(texture), new BlendingAttribute(1f),ColorAttribute.createDiffuse(Color.CYAN));
labelModel = ModelMaker.createRectangle(0, 0, 400,400, 0, mat);
labelInstance = new ModelInstance(labelModel);
labelInstance.userData = MyShaderProvider.shadertypes.distancefield;
以及生成纹理的代码;
private Texture generateTexture(String text) {
String Letters=text;
Pixmap textPixmap = new Pixmap(TITLE_WIDTH, TITLE_HEIGHT, Format.RGBA8888);
BitmapFontData data = DefaultStyles.standdardFont.getData(); //new BitmapFontData(Gdx.files.internal(data.imagePaths[0]), true);
Pixmap fontPixmap = new Pixmap(Gdx.files.internal(data.imagePaths[0]));
// draw the character onto our base pixmap
int totalwidth=0;
int current_testedwidth=0;
int currentX=0;
float scaledown = 1f;
Glyph defaultglyph = data.getGlyph(Letters.charAt(0));
int totalheight=defaultglyph.height+9;
Gdx.app.log(logstag,"scaledown="+scaledown);
double lastremainder =0;
int yp=0;
for (int i = 0; i < Letters.length(); i++) {
Glyph glyph = data.getGlyph(Letters.charAt(i));
if (glyph==null){
glyph=defaultglyph; //temp
}
if (Letters.charAt(i) == '\n'){
Gdx.app.log(logstag,"______________adding line=");
//new line
yp=(int) (yp+(defaultglyph.height* scaledown)+5);
currentX=0;
}
int cwidth = (int)(glyph.width * scaledown);
int cheight = (int)(glyph.height * scaledown);
int yglyphoffset = (int) (glyph.yoffset * scaledown);
textPixmap.drawPixmap(
fontPixmap,
glyph.srcX,
glyph.srcY,
glyph.width,
glyph.height+1,
0+currentX+glyph.xoffset,
0+(yp+(yglyphoffset )),//+(TILE_HEIGHT - (cheight)) / 2,
cwidth,
cheight);
double newprecisepos = ((glyph.xadvance+2) * scaledown)+lastremainder;//glyph.width+3
lastremainder = newprecisepos - Math.floor(newprecisepos);
int newpos = (int) (Math.floor(newprecisepos));
currentX=currentX + newpos;
}
return new Texture(textPixmap,true);
}
它应该看起来这么糟糕吗?
如果需要,我会发布 glsl 的东西,但是(我认为)缩小应该比这更好,不管没有? :?
任何帮助表示赞赏。
【问题讨论】:
-
看起来您生成的纹理可能不支持 mip 映射。将过滤器设置为 MipMapLinearLinear 是不够的。您还必须首先创建一个 MipMapped 纹理。
-
我按照本指南进行操作; github.com/libgdx/libgdx/wiki/Distance-field-fonts 说要使用 mipmapping,但没有说你需要对它做任何特别的事情。位图字体是由 Hiero 生成的,看着 png 我看不到任何 mipmap。
-
BitmapFont 文件不指定 mip 映射。 mips 由 Texture 构造函数在运行时生成。确保在构造纹理时提供构造函数的第二个参数
true。如果省略它,Texture 将不支持 mip 映射。也许你已经这样做了,但我看不到你的generateTexture方法。 -
我相信我正在这样做 - 请参阅上面添加的新 sn-p 末尾的 return 语句。我认为它可以从像素图制作 mipmap?
-
嗯,另一个原因可能是你的字形有这么细的线条。尝试逐渐增加着色器中的
smoothing常量,看看它是否开始看起来更好。
标签: libgdx