Skip to content

Commit a7106b2

Browse files
correct blending mode for text, but still terrible font rendering :(
1 parent 0cbcf42 commit a7106b2

File tree

8 files changed

+46
-18
lines changed

8 files changed

+46
-18
lines changed

Flamui.Components/DropDown.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ public override void Build(Ui ui)
2929

3030
ui.Text(SelectedOption.ToString() ?? string.Empty).Color(ColorPalette.TextColor);
3131

32-
// ui.SvgImage("./Icons/expand_more.svg");
32+
using (ui.Div().Height(23).Width(23))
33+
{
34+
ui.SvgImage("Icons/TVG/expand_more.tvg");
35+
}
3336

3437
if (_isExpanded)
3538
{

Flamui/Drawing/FontLoader.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,14 @@ public unsafe AtlasGlyphInfo FindGlyphEntry(char c, float resolutionMultiplier)
154154

155155
Console.WriteLine($"glyph cache miss: {c}:{resolutionMultiplier}, inserting into slot {entry.SlotNumber}");
156156

157-
for (var i = 0; i < bitmapSpan.Length; i++) //correct upwards for clearer text, not sure why we need to do it...
158-
{
159-
ref var b = ref bitmapSpan[i];
160-
161-
var f = (double)b;
162-
f = 255 * Math.Pow(f / 255, 0.5f);
163-
b = (byte)f;
164-
}
157+
// for (var i = 0; i < bitmapSpan.Length; i++) //correct upwards for clearer text, not sure why we need to do it...
158+
// {
159+
// ref var b = ref bitmapSpan[i];
160+
//
161+
// var f = (double)b;
162+
// f = 255 * Math.Pow(f / 255, 0.5f);
163+
// b = (byte)f;
164+
// }
165165

166166
GpuTexture.Gl.BindTexture(TextureTarget.Texture2D, GpuTexture.TextureId);
167167
GpuTexture.Gl.PixelStore(PixelStoreParameter.UnpackAlignment, 1);

Flamui/Drawing/GlCanvas.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,9 @@ public void Start()
241241
_renderer.Gl.StencilMask(0xFF);
242242
_renderer.Gl.StencilFunc(StencilFunction.Always, 1, 0xFF);
243243

244-
244+
// _renderer.Gl.Enable(EnableCap.FramebufferSrgb);
245+
_renderer.Gl.Enable(EnableCap.Blend);
246+
_renderer.Gl.BlendFunc(BlendingFactor.One, BlendingFactor.OneMinusSrcAlpha);
245247
}
246248

247249
public void Flush()

Flamui/Drawing/Renderer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ public unsafe GpuTexture UploadTexture(Bitmap bitmap)
205205

206206
Gl.TexParameterI(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
207207
Gl.TexParameterI(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);
208-
Gl.TexParameterI(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
209-
Gl.TexParameterI(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
208+
Gl.TexParameterI(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
209+
Gl.TexParameterI(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
210210

211211
Gl.BindTexture(TextureTarget.Texture2D, 0);
212212

Flamui/Drawing/Shaders/main_fragment.glsl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ void main()
2020
}else if(texture_type == 1){
2121
out_color = texture(uTextures[int(texture_id)], frag_texCoords);
2222
}else if(texture_type == 2){
23-
out_color = texture(uTextures[int(texture_id)], frag_texCoords).r * frag_color;
23+
float alpha = texture(uTextures[int(texture_id)], frag_texCoords).r;
24+
out_color = vec4(frag_color.rgb * alpha, alpha);
2425
// out_color = vec4(1, 0, 0, 1);
2526
}
2627
}else{
@@ -50,6 +51,8 @@ void main()
5051
discard;
5152
}
5253

53-
out_color = vec4(frag_color.r, frag_color.g, frag_color.b, frag_color.a * opacity);
54+
opacity *= frag_color.a;
55+
56+
out_color = vec4(frag_color.r * opacity, frag_color.g * opacity, frag_color.b * opacity, opacity);
5457
}
5558
}

Flamui/UiWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ private void RenderToCanvas()
304304

305305
if (!RenderContextAreSame(RenderContext, LastRenderContext))
306306
{
307-
RenderContext.PrintCommands();
307+
// RenderContext.PrintCommands();
308308

309309
_renderer.Gl.Viewport(Window.Size);
310310
RenderContext.Rerender(_renderer);

Flamui/VgAtlas.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ public unsafe AtlasEntry GetAtlasEntry(int svgHash, Span<byte> vgData, uint widt
9393
BitmapFormat = BitmapFormat.RGBA
9494
};
9595

96+
//premultiply alpha
97+
for (int i = 0; i < bitmap.Height * bitmap.Width; i++)
98+
{
99+
var a = (float)bitmap.Data[i * 4 + 3] / 255;
100+
101+
bitmap.Data[i * 4 + 0] = (byte)((float)bitmap.Data[i * 4 + 0] * a);
102+
bitmap.Data[i * 4 + 1] = (byte)((float)bitmap.Data[i * 4 + 1] * a);
103+
bitmap.Data[i * 4 + 2] = (byte)((float)bitmap.Data[i * 4 + 2] * a);
104+
}
105+
96106
bitmap.CopyTo(tempBitmap);
97107
// tempBitmap.PrintToConsole();
98108

Sample.LayoutTest/Program.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Flamui;
2+
using Flamui.Components;
23

34
/*
45
* Todo
@@ -24,7 +25,7 @@ public class LayoutTest : FlamuiComponent
2425
"Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
2526

2627
private string input2 = "anita max wynn";
27-
private string selectedOption = "";
28+
private string selectedOption = "John";
2829

2930
private string[] icons =
3031
[
@@ -49,7 +50,9 @@ public class LayoutTest : FlamuiComponent
4950

5051
public override void Build(Ui ui)
5152
{
52-
using (ui.Div().Margin(10).Color(C.Gray6).ScrollVertical().Clip().Padding(10))
53+
ui.CascadingValues.TextColor = C.White;
54+
55+
using (ui.Div().Margin(10).Color(C.Gray6).ScrollVertical().Clip().Padding(10).Rounded(10))
5356
{
5457
foreach (var icon in icons)
5558
{
@@ -61,9 +64,16 @@ public override void Build(Ui ui)
6164
}
6265
}
6366

64-
using (ui.Div().Color(C.Green7))
67+
using (ui.Div().Color(C.Gray6).Padding(10).Rounded(10).Margin(10).Gap(10))
6568
{
69+
var dd = ui.CreateDropDown(selectedOption);
70+
dd.Component.Option("John");
71+
dd.Component.Option("Albert");
72+
dd.Component.Option("Div");
73+
dd.Component.Option("Size");
74+
dd.Build(out selectedOption);
6675

76+
ui.StyledInput(ref input2);
6777
}
6878
}
6979
}

0 commit comments

Comments
 (0)