File tree Expand file tree Collapse file tree 6 files changed +31
-11
lines changed
kotlin/com/lambda/graphics
resources/assets/lambda/shaders/fragment/renderer Expand file tree Collapse file tree 6 files changed +31
-11
lines changed Original file line number Diff line number Diff line change @@ -140,8 +140,13 @@ class FontRenderer(
140140
141141 override fun render () {
142142 shader.use()
143+
143144 font.glyphs.bind()
144- // emojis.glyphs.bind() // You have to modify the uniform in the shader to use the correct texture
145+ shader[" u_FontTexture" ] = 0
146+
147+ emojis.glyphs.bind()
148+ shader[" u_EmojiTexture" ] = 1
149+
145150 super .render()
146151 }
147152
Original file line number Diff line number Diff line change @@ -6,4 +6,4 @@ class CharInfo(
66 val size : Vec2d ,
77 val uv1 : Vec2d ,
88 val uv2 : Vec2d
9- )
9+ )
Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ class EmojiGlyphs(zipUrl: String) {
5555
5656 val uv1 = Vec2d (x.toDouble(), y.toDouble()) * texelSize
5757 val uv2 = Vec2d (x, y).plus(dimensions) * texelSize
58- emojiMap[name] = CharInfo (dimensions, uv1, uv2)
58+ emojiMap[name] = CharInfo (dimensions, uv1 * - 1.0 , uv2 * - 1.0 )
5959
6060 x + = emoji.width
6161 }
@@ -69,11 +69,15 @@ class EmojiGlyphs(zipUrl: String) {
6969
7070 fun bind () {
7171 with (fontTexture) {
72- bind()
72+ bind(GL_TEXTURE_SLOT )
7373 setLOD(FontSettings .lodBias.toFloat())
7474 }
7575 }
7676
7777 fun getEmoji (emoji : String ): CharInfo ? =
7878 emojiMap[emoji]
79+
80+ companion object {
81+ private const val GL_TEXTURE_SLOT = 1
82+ }
7983}
Original file line number Diff line number Diff line change @@ -63,7 +63,7 @@ class FontGlyphs(font: Font) {
6363
6464 fun bind () {
6565 with (fontTexture) {
66- bind()
66+ bind(GL_TEXTURE_SLOT )
6767 setLOD(FontSettings .lodBias.toFloat())
6868 }
6969 }
@@ -72,6 +72,9 @@ class FontGlyphs(font: Font) {
7272 charMap[char.code]
7373
7474 companion object {
75+ // The allocated texture slot
76+ private const val GL_TEXTURE_SLOT = 0
77+
7578 // The space between glyphs is necessary to prevent artifacts from appearing when the font texture is blurred
7679 private const val STEP = 2
7780
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ abstract class Texture {
1414
1515 protected abstract fun init ()
1616
17- open fun bind () = bindTexture(id)
17+ open fun bind (slot : Int = 0 ) = bindTexture(id)
1818
1919 override fun equals (other : Any? ): Boolean {
2020 if (this == = other) return true
@@ -26,4 +26,4 @@ abstract class Texture {
2626 }
2727
2828 override fun hashCode () = id
29- }
29+ }
Original file line number Diff line number Diff line change 11#version 330 core
22
3- uniform sampler2D u_Texture;
3+ uniform sampler2D u_FontTexture;
4+ uniform sampler2D u_EmojiTexture;
45
56in vec2 v_TexCoord;
67in vec4 v_Color;
78
89out vec4 color;
910
1011void main() {
11- float alpha = texture(u_Texture, v_TexCoord).a;
12- color = vec4 (v_Color.rgb, v_Color.a * alpha);
13- }
12+ vec4 tex;
13+
14+ if (v_TexCoord.x > 0.0 ) {
15+ tex = texture(u_FontTexture, v_TexCoord);
16+ } else {
17+ tex = texture(u_EmojiTexture, v_TexCoord);
18+ }
19+
20+ color = tex * v_Color;
21+ }
You can’t perform that action at this time.
0 commit comments