@@ -34,6 +34,7 @@ FetchContent_MakeAvailable(raylib)
|
||||
FetchContent_Declare(
|
||||
msdfgen
|
||||
GIT_REPOSITORY https://github.com/Chlumsky/msdfgen.git
|
||||
GIT_TAG "v1.12.1"
|
||||
GIT_SHALLOW 1
|
||||
)
|
||||
set(MSDFGEN_BUILD_STANDALONE OFF)
|
||||
|
||||
@@ -130,7 +130,7 @@ auto TextRenderer::generate_glyph(FontRuntime &rt, FontData &fd,
|
||||
msdfgen::FONT_SCALING_EM_NORMALIZED, &advance_em))
|
||||
return std::nullopt;
|
||||
shape.normalize();
|
||||
msdfgen::edgeColoringSimple(shape, 3.0);
|
||||
msdfgen::edgeColoringInkTrap(shape, 3.0);
|
||||
auto bounds = shape.getBounds();
|
||||
float const width_em = static_cast<float>(bounds.r - bounds.l);
|
||||
float const height_em = static_cast<float>(bounds.t - bounds.b);
|
||||
@@ -172,14 +172,11 @@ auto TextRenderer::generate_glyph(FontRuntime &rt, FontData &fd,
|
||||
int const dst_y = bmp_h - 1 - y;
|
||||
for (int x = 0; x < bmp_w; ++x) {
|
||||
float const *px = msdf_bitmap(x, y);
|
||||
auto const clamp = [](float v) {
|
||||
printf("%.2f ", v);
|
||||
return static_cast<unsigned char>(
|
||||
std::lround(std::clamp(v, 0.0f, 1.0f) * 255.0f));
|
||||
};
|
||||
auto const r = msdfgen::pixelFloatToByte(px[0]);
|
||||
auto const g = msdfgen::pixelFloatToByte(px[1]);
|
||||
auto const b = msdfgen::pixelFloatToByte(px[2]);
|
||||
buffer[static_cast<size_t>(dst_y) * bmp_w + x]
|
||||
= Color { clamp(px[0]), clamp(px[1]), clamp(px[2]), 255 };
|
||||
printf("\n");
|
||||
= Color { r, g, b, 255 };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,11 +234,15 @@ auto TextRenderer::ensure_glyph(FontRuntime &rt, FontData &fd, u32 glyph_index,
|
||||
|
||||
TextRenderer::TextRenderer()
|
||||
{
|
||||
static char const msdf_vs_data[] {
|
||||
#embed "base.vs"
|
||||
, 0
|
||||
};
|
||||
static char const msdf_fs_data[] {
|
||||
#embed "msdf.fs"
|
||||
, 0
|
||||
};
|
||||
m_msdf_shader = LoadShaderFromMemory(nullptr, msdf_fs_data);
|
||||
m_msdf_shader = LoadShaderFromMemory(msdf_vs_data, msdf_fs_data);
|
||||
assert(IsShaderValid(m_msdf_shader));
|
||||
m_px_range_uniform = GetShaderLocation(m_msdf_shader, "pxRange");
|
||||
}
|
||||
@@ -347,12 +348,11 @@ auto TextRenderer::draw_text(FontHandle const font, std::string_view const text,
|
||||
float pen_y_em = 0.0f;
|
||||
rt.frame_stamp++;
|
||||
|
||||
// BeginShaderMode(m_msdf_shader);
|
||||
BeginShaderMode(m_msdf_shader);
|
||||
if (m_px_range_uniform >= 0) {
|
||||
float shader_px_range = rt.px_range;
|
||||
// SetShaderValue(
|
||||
// m_msdf_shader, m_px_range_uniform, &shader_px_range,
|
||||
// SHADER_UNIFORM_FLOAT);
|
||||
SetShaderValue(m_msdf_shader, m_px_range_uniform, &shader_px_range,
|
||||
SHADER_UNIFORM_FLOAT);
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < length; ++i) {
|
||||
@@ -395,7 +395,7 @@ auto TextRenderer::draw_text(FontHandle const font, std::string_view const text,
|
||||
pen_y_em += hb_to_em(positions[i].y_advance, rt.units_per_em);
|
||||
}
|
||||
|
||||
// EndShaderMode();
|
||||
EndShaderMode();
|
||||
hb_buffer_destroy(buffer);
|
||||
|
||||
auto const draw_end = std::chrono::steady_clock::now();
|
||||
@@ -426,7 +426,7 @@ auto TextRenderer::load_font(std::filesystem::path const &path)
|
||||
runtime->pen_x = kAtlasPadding;
|
||||
runtime->pen_y = kAtlasPadding;
|
||||
runtime->row_height = 0;
|
||||
runtime->px_range = kDefaultPxRange;
|
||||
runtime->px_range = 0.05; // kDefaultPxRange;
|
||||
runtime->em_scale = kDefaultEmScale;
|
||||
runtime->frame_stamp = 0;
|
||||
runtime->units_per_em
|
||||
|
||||
19
src/base.vs
Normal file
19
src/base.vs
Normal file
@@ -0,0 +1,19 @@
|
||||
#version 100
|
||||
|
||||
attribute vec3 vertexPosition;
|
||||
attribute vec2 vertexTexCoord;
|
||||
attribute vec3 vertexNormal;
|
||||
attribute vec4 vertexColor;
|
||||
|
||||
uniform mat4 mvp;
|
||||
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
fragTexCoord = vertexTexCoord;
|
||||
fragColor = vertexColor;
|
||||
|
||||
gl_Position = mvp*vec4(vertexPosition, 1.0);
|
||||
}
|
||||
Reference in New Issue
Block a user