Java – how to render libgdx bitmapfont so that its pixel color is opposite to the background?
•
Java
either
sb.setBlendFunction(GL10.GL_ONE_MINUS_DST_COLOR,GL10.GL_ZERO); sb.begin(); font.setColor(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);
either
Gdx.gl10.glEnable(GL10.GL_COLOR_LOGIC_OP); Gdx.gl10.glLogicOp(GL10.GL_XOR); sb.begin(); font.setColor(1,1); for (LineRect s: vertices){ font.draw(sb,s.y); } sb.end(); Gdx.gl10.glDisable(GL10.GL_COLOR_LOGIC_OP);
Working for me, what did I do wrong? How do I solve it?
Our idea is to draw a font, which consists of quadrilateral with partially transparent texture. It will always be visible unless the background is 50% gray Black background = white font, and so on
Solution
You need to test the brightness of the background color Here is a method I made for AWT color. It should be easy to adapt to the libgdx color class:
/** * 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); }
If brightness < 1 128, use light foreground, otherwise use dark foreground
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码