gpt4 book ai didi

java - 如何渲染 Libgdx 位图字体,使其像素颜色与背景颜色相反?

转载 作者:太空宇宙 更新时间:2023-11-03 10:53:59 27 4
gpt4 key购买 nike

都不是

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% 灰色。背景黑色 = 字体呈现白色,等等。

最佳答案

您需要测试背景颜色的亮度。这是我为 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,则使用亮前景,否则使用暗前景。

关于java - 如何渲染 Libgdx 位图字体,使其像素颜色与背景颜色相反?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8659006/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com