作为着色器的新手,当我成功(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的东西,但是(我认为)缩小应该比这更好吗? :
任何帮助表示感谢。
答案 0 :(得分:0)
并不完全令人满意,但在环顾四周后,对着色器进行了调整,产生了更好的效果; http://www.java-gaming.org/index.php?topic=33612.0
基本上你需要添加超级采样。 奇怪的是,似乎没有mip-maps可以更好地工作。