From 1c0b7c21b65dc3d20138a4b75771b033a017a0c1 Mon Sep 17 00:00:00 2001 From: Moritz Zwerger Date: Tue, 16 Jan 2024 18:13:51 +0100 Subject: [PATCH] font texture: properly copy alpha channel to rgb components This finally fixes all font rendering issues with compression. Previously the font textures were in the aaaa format, since 1.20 they seem to be in the 111a format (which is completely valid and reduces file size). the problem is, that the with font compression just the red channel will be used. This one is always 1, so all chars are are quare on screen. Not the alpha channel is force copied to the rgb channels --- .../opengl/texture/OpenGLFontTextureArray.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/texture/OpenGLFontTextureArray.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/texture/OpenGLFontTextureArray.kt index 3eaae313b..3053442f3 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/texture/OpenGLFontTextureArray.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/texture/OpenGLFontTextureArray.kt @@ -24,6 +24,7 @@ import de.bixilon.minosoft.gui.rendering.system.base.texture.array.TextureArrayS import de.bixilon.minosoft.gui.rendering.system.base.texture.array.font.FontCompressions import de.bixilon.minosoft.gui.rendering.system.base.texture.array.font.FontTextureArray import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.Texture +import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.file.PNGTexture import de.bixilon.minosoft.gui.rendering.system.opengl.OpenGLRenderSystem import de.bixilon.minosoft.gui.rendering.system.opengl.texture.OpenGLTextureUtil.glFormat import de.bixilon.minosoft.gui.rendering.system.opengl.texture.OpenGLTextureUtil.glType @@ -62,6 +63,9 @@ class OpenGLFontTextureArray( val buffer = texture.data.buffer buffer.data.position(0) buffer.data.limit(buffer.data.capacity()) + if (compression != FontCompressions.NONE && texture is PNGTexture) { + buffer.data.copyAlphaToRGB() + } glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, renderData.index, buffer.size.x, buffer.size.y, 1, buffer.glFormat, buffer.glType, buffer.data) } @@ -108,5 +112,17 @@ class OpenGLFontTextureArray( private companion object { const val RESOLUTION = 1024 + + + private fun ByteBuffer.copyAlphaToRGB() { + val pixels = this.limit() / 4 + for (index in 0 until pixels) { + val offset = index * 4 + val alpha = this[offset + 3] + this.put(offset + 0, alpha) + this.put(offset + 1, alpha) + this.put(offset + 2, alpha) + } + } } }