fixed font rendering
This commit is contained in:
parent
19c28de4fd
commit
5eca5811fb
BIN
assets/NuberNext.otf
Normal file
BIN
assets/NuberNext.otf
Normal file
Binary file not shown.
BIN
assets/NuberNextCondensed-DemiBold.otf
Normal file
BIN
assets/NuberNextCondensed-DemiBold.otf
Normal file
Binary file not shown.
BIN
assets/Roboto.ttf
Normal file
BIN
assets/Roboto.ttf
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
2
dub.json
2
dub.json
@ -13,7 +13,7 @@
|
|||||||
"sourcePaths": ["src/editor", "src/dlib", "src/dlib/external/xxhash", "src/VulkanRenderer"],
|
"sourcePaths": ["src/editor", "src/dlib", "src/dlib/external/xxhash", "src/VulkanRenderer"],
|
||||||
"libs-linux": ["xcb", "X11", "X11-xcb", "vulkan", "stdc++", "xcb-xfixes", "freetype"],
|
"libs-linux": ["xcb", "X11", "X11-xcb", "vulkan", "stdc++", "xcb-xfixes", "freetype"],
|
||||||
"libs-windows": [],
|
"libs-windows": [],
|
||||||
"versions": ["VK_DEBUG_PRINTF"],
|
"versions": [],
|
||||||
"preGenerateCommands-linux": ["./build.sh"],
|
"preGenerateCommands-linux": ["./build.sh"],
|
||||||
"preGenerateCommands-windows": [],
|
"preGenerateCommands-windows": [],
|
||||||
"dflags": ["-Xcc=-mno-sse", "-P-I/usr/include/freetype2", "-Jbuild", "-Jassets"],
|
"dflags": ["-Xcc=-mno-sse", "-P-I/usr/include/freetype2", "-Jbuild", "-Jassets"],
|
||||||
|
|||||||
2
src/dlib
2
src/dlib
@ -1 +1 @@
|
|||||||
Subproject commit f211a29857111a6be26b9cb0e9799ffcb7631df6
|
Subproject commit 69f5cd1a76ce0ee4f61201a5cae460664a5d8ca9
|
||||||
@ -10,6 +10,7 @@ import buffer;
|
|||||||
import std.stdio;
|
import std.stdio;
|
||||||
import std.exception;
|
import std.exception;
|
||||||
|
|
||||||
|
//const u8[] FONT_BYTES = import("Roboto.ttf");
|
||||||
const u8[] FONT_BYTES = import("pc-9800.ttf");
|
const u8[] FONT_BYTES = import("pc-9800.ttf");
|
||||||
const u8[] VERTEX_BYTES = import("gui.vert.spv");
|
const u8[] VERTEX_BYTES = import("gui.vert.spv");
|
||||||
const u8[] FRAGMENT_BYTES = import("gui.frag.spv");
|
const u8[] FRAGMENT_BYTES = import("gui.frag.spv");
|
||||||
@ -65,6 +66,7 @@ struct Vertex
|
|||||||
f32 corner_radius;
|
f32 corner_radius;
|
||||||
f32 edge_softness;
|
f32 edge_softness;
|
||||||
f32 raised;
|
f32 raised;
|
||||||
|
u32 texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -74,14 +76,19 @@ Cycle(Editor* ed)
|
|||||||
|
|
||||||
Reset(&ed.temp_arena);
|
Reset(&ed.temp_arena);
|
||||||
|
|
||||||
f32 pos = 0.0;
|
|
||||||
f32 h = ed.atlas_buf.atlas.size;
|
|
||||||
DrawBuffer(ed, 0.0, 0.0, h, ed.active_buffer);
|
|
||||||
|
|
||||||
//DrawRect(ed, 200.0, 200.0, 300.0, 300.0, 0.0, 0.0, 0.0, Vec4(0.2, 0.4, 0.8, 1.0));
|
//DrawRect(ed, 200.0, 200.0, 300.0, 300.0, 0.0, 0.0, 0.0, Vec4(0.2, 0.4, 0.8, 1.0));
|
||||||
//DrawRect(ed, 330.0, 330.0, 430.0, 430.0, 0.0, 0.0, 0.0, Vec4(0.2, 0.4, 0.8, 1.0));
|
//DrawRect(ed, 330.0, 330.0, 430.0, 430.0, 0.0, 0.0, 0.0, Vec4(0.2, 0.4, 0.8, 1.0));
|
||||||
DrawRect(ed, 450.0, 450.0, 550.0, 550.0, 0.0, 5.0, 1.0, 20.0, [Vec4(0.2, 0.5, 0.9, 1.0), Vec4(Vec3(0.8), 1.0), Vec4(Vec3(0.8), 1.0), Vec4(Vec3(0.6), 1.0)]);
|
Vec4 col = Vec4(0.2, 0.5, 0.9, 1.0);
|
||||||
DrawRect(ed, 450.0, 450.0, 550.0, 550.0, 2.0, 5.0, 1.0, 20.0, [Vec4(Vec3(0.0), 1.0), Vec4(Vec3(0.0), 1.0), Vec4(Vec3(0.0), 1.0), Vec4(Vec3(0.0), 1.0)]);
|
Vec4 col2 = Vec4(0.2, 0.4, 0.7, 1.0);
|
||||||
|
Vec4 col3 = Vec4(0.2, 0.3, 0.65, 1.0);
|
||||||
|
Vec4 black = Vec4(0.0, 0.0, 0.0, 1.0);
|
||||||
|
DrawRect(ed, -1000.0, -1000.0, 3000.0, 3000.0, 0.0, 0.0, 0.0, 0.0, [black, black, black, black]);
|
||||||
|
//DrawRect(ed, 450.0, 450.0, 550.0, 550.0, 2.0, 5.0, 0.2, 20.0, [black, black, black, black]);
|
||||||
|
|
||||||
|
f32 pos = 0.0;
|
||||||
|
f32 h = ed.atlas_buf.atlas.size;
|
||||||
|
DrawBuffer(ed, 0.0, 0.0, h, ed.active_buffer);
|
||||||
|
|
||||||
BeginFrame(&ed.rd);
|
BeginFrame(&ed.rd);
|
||||||
|
|
||||||
@ -148,7 +155,7 @@ CreateEditor(PlatformWindow* window, u8[] buffer_data, u8[] buffer_name)
|
|||||||
Arena arena = CreateArena(MB(32));
|
Arena arena = CreateArena(MB(32));
|
||||||
|
|
||||||
FontFace font = OpenFont(cast(u8[])FONT_BYTES);
|
FontFace font = OpenFont(cast(u8[])FONT_BYTES);
|
||||||
FontAtlasBuf atlas_buf = CreateAtlas(&arena, font, 14.0, 256);
|
FontAtlasBuf atlas_buf = CreateAtlas(&arena, font, 16.0, 256);
|
||||||
|
|
||||||
Editor editor = {
|
Editor editor = {
|
||||||
window: window,
|
window: window,
|
||||||
@ -186,7 +193,7 @@ CreateEditor(PlatformWindow* window, u8[] buffer_data, u8[] buffer_name)
|
|||||||
editor.desc_set = AllocDescSet(&editor.rd, editor.desc_set_layout);
|
editor.desc_set = AllocDescSet(&editor.rd, editor.desc_set_layout);
|
||||||
editor.pipeline_layout = CreatePipelineLayout(&editor.rd, editor.desc_set_layout, PushConst.sizeof);
|
editor.pipeline_layout = CreatePipelineLayout(&editor.rd, editor.desc_set_layout, PushConst.sizeof);
|
||||||
|
|
||||||
Attribute[12] attributes = [
|
Attribute[13] attributes = [
|
||||||
{ binding: 0, location: 0, format: FMT.RGBA_F32, offset: Vertex.cols.offsetof + Vec4.sizeof * 0},
|
{ binding: 0, location: 0, format: FMT.RGBA_F32, offset: Vertex.cols.offsetof + Vec4.sizeof * 0},
|
||||||
{ binding: 0, location: 1, format: FMT.RGBA_F32, offset: Vertex.cols.offsetof + Vec4.sizeof * 1},
|
{ binding: 0, location: 1, format: FMT.RGBA_F32, offset: Vertex.cols.offsetof + Vec4.sizeof * 1},
|
||||||
{ binding: 0, location: 2, format: FMT.RGBA_F32, offset: Vertex.cols.offsetof + Vec4.sizeof * 2},
|
{ binding: 0, location: 2, format: FMT.RGBA_F32, offset: Vertex.cols.offsetof + Vec4.sizeof * 2},
|
||||||
@ -199,6 +206,7 @@ CreateEditor(PlatformWindow* window, u8[] buffer_data, u8[] buffer_name)
|
|||||||
{ binding: 0, location: 9, format: FMT.R_F32, offset: Vertex.corner_radius.offsetof },
|
{ binding: 0, location: 9, format: FMT.R_F32, offset: Vertex.corner_radius.offsetof },
|
||||||
{ binding: 0, location: 10, format: FMT.R_F32, offset: Vertex.edge_softness.offsetof },
|
{ binding: 0, location: 10, format: FMT.R_F32, offset: Vertex.edge_softness.offsetof },
|
||||||
{ binding: 0, location: 11, format: FMT.R_F32, offset: Vertex.raised.offsetof },
|
{ binding: 0, location: 11, format: FMT.R_F32, offset: Vertex.raised.offsetof },
|
||||||
|
{ binding: 0, location: 12, format: FMT.R_U32, offset: Vertex.texture.offsetof },
|
||||||
];
|
];
|
||||||
|
|
||||||
GfxPipelineInfo ui_info = {
|
GfxPipelineInfo ui_info = {
|
||||||
@ -227,7 +235,7 @@ CreateEditor(PlatformWindow* window, u8[] buffer_data, u8[] buffer_name)
|
|||||||
|
|
||||||
Write(&editor.rd, editor.desc_set, &editor.font_atlas, 0, DT.Image);
|
Write(&editor.rd, editor.desc_set, &editor.font_atlas, 0, DT.Image);
|
||||||
|
|
||||||
SetClearColors(&editor.rd, [0.149, 0.607, 0.768, 1.0], [0.0, 0.0, 0.0, 0.0]);
|
SetClearColors(&editor.rd, [0.0, 0.0, 0.0, 1.0], [0.0, 0.0, 0.0, 0.0]);
|
||||||
|
|
||||||
Reset(&editor.temp_arena);
|
Reset(&editor.temp_arena);
|
||||||
|
|
||||||
@ -365,13 +373,15 @@ DrawGlyph(Editor* ed, Glyph* glyph, f32 scale, f32* x_pos, f32 y, Vec4 col = Vec
|
|||||||
v.cols[2] = col;
|
v.cols[2] = col;
|
||||||
v.cols[3] = col;
|
v.cols[3] = col;
|
||||||
|
|
||||||
|
v.texture = 1;
|
||||||
|
|
||||||
AddUIIndices(ed);
|
AddUIIndices(ed);
|
||||||
}
|
}
|
||||||
|
|
||||||
*x_pos += glyph.advance * scale;
|
*x_pos += glyph.advance * scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
pragma(inline) void
|
||||||
DrawRect(Editor* ed, f32 p0_x, f32 p0_y, f32 p1_x, f32 p1_y, f32 border, f32 corner, f32 softness, f32 raised, Vec4[4] cols)
|
DrawRect(Editor* ed, f32 p0_x, f32 p0_y, f32 p1_x, f32 p1_y, f32 border, f32 corner, f32 softness, f32 raised, Vec4[4] cols)
|
||||||
{
|
{
|
||||||
// Y reversed
|
// Y reversed
|
||||||
|
|||||||
@ -5,7 +5,9 @@
|
|||||||
|
|
||||||
#include "gui.layout"
|
#include "gui.layout"
|
||||||
|
|
||||||
layout (location = 0) in struct FragDataIn {
|
layout (location = 0) flat in uint in_has_texture;
|
||||||
|
|
||||||
|
layout (location = 1) in struct FragDataIn {
|
||||||
vec4 color;
|
vec4 color;
|
||||||
vec2 uv;
|
vec2 uv;
|
||||||
vec2 dst_pos;
|
vec2 dst_pos;
|
||||||
@ -17,6 +19,7 @@ layout (location = 0) in struct FragDataIn {
|
|||||||
float border_thickness;
|
float border_thickness;
|
||||||
} FD;
|
} FD;
|
||||||
|
|
||||||
|
|
||||||
layout (location = 0) out vec4 FragColor;
|
layout (location = 0) out vec4 FragColor;
|
||||||
|
|
||||||
float RoundedRectSDF(vec2 pos, vec2 center, vec2 half_size, float radius)
|
float RoundedRectSDF(vec2 pos, vec2 center, vec2 half_size, float radius)
|
||||||
@ -65,9 +68,18 @@ void main()
|
|||||||
border_factor = inside_f;
|
border_factor = inside_f;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 tex_color = texture(sampler2D(SpriteAtlas, SamplerNearest), FD.uv);
|
vec4 inv_gamma = vec4(1.4);
|
||||||
debugPrintfEXT("tex_color %v4f", tex_color);
|
vec4 gamma = vec4(1.0/1.4);
|
||||||
vec4 out_color = FD.color * tex_color * sdf_factor * border_factor;
|
|
||||||
|
vec4 tex_color = vec4(1.0);
|
||||||
|
if (in_has_texture != 0)
|
||||||
|
{
|
||||||
|
tex_color = texture(sampler2D(SpriteAtlas, SamplerNearest), FD.uv);
|
||||||
|
//tex_color = pow(tex_color, gamma);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 color = FD.color;
|
||||||
|
vec4 out_color = color * tex_color * sdf_factor * border_factor;
|
||||||
|
|
||||||
FragColor = out_color;
|
FragColor = out_color;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,8 +16,11 @@ layout (location = 8) in float border_thickness;
|
|||||||
layout (location = 9) in float corner_radius;
|
layout (location = 9) in float corner_radius;
|
||||||
layout (location = 10) in float edge_softness;
|
layout (location = 10) in float edge_softness;
|
||||||
layout (location = 11) in float raised;
|
layout (location = 11) in float raised;
|
||||||
|
layout (location = 12) in uint in_has_texture;
|
||||||
|
|
||||||
layout (location = 0) out struct FragDataOut {
|
layout (location = 0) flat out uint out_has_texture;
|
||||||
|
|
||||||
|
layout (location = 1) out struct FragDataOut {
|
||||||
vec4 color;
|
vec4 color;
|
||||||
vec2 uv;
|
vec2 uv;
|
||||||
vec2 dst_pos;
|
vec2 dst_pos;
|
||||||
@ -29,6 +32,7 @@ layout (location = 0) out struct FragDataOut {
|
|||||||
float border_thickness;
|
float border_thickness;
|
||||||
} FragData;
|
} FragData;
|
||||||
|
|
||||||
|
|
||||||
vec2 Vertices[4] = vec2[4](
|
vec2 Vertices[4] = vec2[4](
|
||||||
vec2(-1.0, -1.0),
|
vec2(-1.0, -1.0),
|
||||||
vec2(-1.0, +1.0),
|
vec2(-1.0, +1.0),
|
||||||
@ -79,6 +83,7 @@ void main()
|
|||||||
FragData.softness = edge_softness;
|
FragData.softness = edge_softness;
|
||||||
FragData.raised = raised;
|
FragData.raised = raised;
|
||||||
FragData.border_thickness = border_thickness;
|
FragData.border_thickness = border_thickness;
|
||||||
|
out_has_texture = in_has_texture;
|
||||||
|
|
||||||
vec4 v_pos = PC.projection * vec4(pos.x, pos.y, 0, 1);
|
vec4 v_pos = PC.projection * vec4(pos.x, pos.y, 0, 1);
|
||||||
gl_Position = vec4(v_pos.x, v_pos.y, 0, 1);
|
gl_Position = vec4(v_pos.x, v_pos.y, 0, 1);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user