How to render Libgdx Bitmapfont so that the color of the pixels is inverse to the background?

Neither

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, sx, sy); } sb.end(); sb.setBlendFunction(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA); 

neither

 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, sx, sy); } sb.end(); Gdx.gl10.glDisable(GL10.GL_COLOR_LOGIC_OP); 

Worked for me, what am I doing wrong? How to fix it?

The idea is to draw a font consisting of ATVs with partially transparent textures, so that it will always be visible unless the background is 50% gray. Background black = font makes white, etc.

+4
source share
1 answer

You need to check the brightness of the background color. here is the method i made for AWT colors should be very easy to adapt to 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 the brightness is <128, use a light foreground, otherwise use a dark foreground.

+1
source

Source: https://habr.com/ru/post/1388340/


All Articles