2011-12-28 42 views
4

无论如何呈现一个Libgdx Bitmapfont,以便它的像素颜色是背景的倒数?

sb.setBlendFunction(GL10.GL_ONE_MINUS_DST_COLOR, GL10.GL_ZERO); 
sb.begin(); 
font.setColor(1, 1, 1, 1); 
for (LineRect s: vertices){ 
    font.draw(sb,""+ s.x+","+.y, s.x, s.y); 
} 
sb.end(); 
sb.setBlendFunction(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA); 

也不

Gdx.gl10.glEnable(GL10.GL_COLOR_LOGIC_OP); 
Gdx.gl10.glLogicOp(GL10.GL_XOR); 

    sb.begin(); 
    font.setColor(1, 1, 1, 1); 
    for (LineRect s: vertices){ 
     font.draw(sb,""+ s.x+","+.y, s.x, s.y); 
    } 
    sb.end(); 


Gdx.gl10.glDisable(GL10.GL_COLOR_LOGIC_OP); 

为我工作,我究竟做错了什么? 我该如何解决它?

这个想法是绘制字体,它包含部分透明纹理的四边形,它总是可见的,除非背景为50%灰色。 背景黑色=字体呈现白色,依此类推。

回答

1

您需要测试背景颜色的亮度。这里是我的AWT的颜色做了一个方法,应该是很容易适应libgdx颜色类:

/** 
* Returns the brightness of the color, between 0 and 255. 
*/ 
public static int getBrightness(Color c) { 
    if (c == null) return -1; 
    return (int) Math.sqrt(
     c.getRed() * c.getRed() * .241 + 
     c.getGreen() * c.getGreen() * .691 + 
     c.getBlue() * c.getBlue() * .068); 
} 

如果亮度< 128,用浅色的前景,也可以使用一个黑暗的前景。