@@ -34,6 +34,7 @@ FetchContent_MakeAvailable(raylib)
|
|||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
msdfgen
|
msdfgen
|
||||||
GIT_REPOSITORY https://github.com/Chlumsky/msdfgen.git
|
GIT_REPOSITORY https://github.com/Chlumsky/msdfgen.git
|
||||||
|
GIT_TAG "v1.12.1"
|
||||||
GIT_SHALLOW 1
|
GIT_SHALLOW 1
|
||||||
)
|
)
|
||||||
set(MSDFGEN_BUILD_STANDALONE OFF)
|
set(MSDFGEN_BUILD_STANDALONE OFF)
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ auto TextRenderer::generate_glyph(FontRuntime &rt, FontData &fd,
|
|||||||
msdfgen::FONT_SCALING_EM_NORMALIZED, &advance_em))
|
msdfgen::FONT_SCALING_EM_NORMALIZED, &advance_em))
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
shape.normalize();
|
shape.normalize();
|
||||||
msdfgen::edgeColoringSimple(shape, 3.0);
|
msdfgen::edgeColoringInkTrap(shape, 3.0);
|
||||||
auto bounds = shape.getBounds();
|
auto bounds = shape.getBounds();
|
||||||
float const width_em = static_cast<float>(bounds.r - bounds.l);
|
float const width_em = static_cast<float>(bounds.r - bounds.l);
|
||||||
float const height_em = static_cast<float>(bounds.t - bounds.b);
|
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;
|
int const dst_y = bmp_h - 1 - y;
|
||||||
for (int x = 0; x < bmp_w; ++x) {
|
for (int x = 0; x < bmp_w; ++x) {
|
||||||
float const *px = msdf_bitmap(x, y);
|
float const *px = msdf_bitmap(x, y);
|
||||||
auto const clamp = [](float v) {
|
auto const r = msdfgen::pixelFloatToByte(px[0]);
|
||||||
printf("%.2f ", v);
|
auto const g = msdfgen::pixelFloatToByte(px[1]);
|
||||||
return static_cast<unsigned char>(
|
auto const b = msdfgen::pixelFloatToByte(px[2]);
|
||||||
std::lround(std::clamp(v, 0.0f, 1.0f) * 255.0f));
|
|
||||||
};
|
|
||||||
buffer[static_cast<size_t>(dst_y) * bmp_w + x]
|
buffer[static_cast<size_t>(dst_y) * bmp_w + x]
|
||||||
= Color { clamp(px[0]), clamp(px[1]), clamp(px[2]), 255 };
|
= Color { r, g, b, 255 };
|
||||||
printf("\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,11 +234,15 @@ auto TextRenderer::ensure_glyph(FontRuntime &rt, FontData &fd, u32 glyph_index,
|
|||||||
|
|
||||||
TextRenderer::TextRenderer()
|
TextRenderer::TextRenderer()
|
||||||
{
|
{
|
||||||
|
static char const msdf_vs_data[] {
|
||||||
|
#embed "base.vs"
|
||||||
|
, 0
|
||||||
|
};
|
||||||
static char const msdf_fs_data[] {
|
static char const msdf_fs_data[] {
|
||||||
#embed "msdf.fs"
|
#embed "msdf.fs"
|
||||||
, 0
|
, 0
|
||||||
};
|
};
|
||||||
m_msdf_shader = LoadShaderFromMemory(nullptr, msdf_fs_data);
|
m_msdf_shader = LoadShaderFromMemory(msdf_vs_data, msdf_fs_data);
|
||||||
assert(IsShaderValid(m_msdf_shader));
|
assert(IsShaderValid(m_msdf_shader));
|
||||||
m_px_range_uniform = GetShaderLocation(m_msdf_shader, "pxRange");
|
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;
|
float pen_y_em = 0.0f;
|
||||||
rt.frame_stamp++;
|
rt.frame_stamp++;
|
||||||
|
|
||||||
// BeginShaderMode(m_msdf_shader);
|
BeginShaderMode(m_msdf_shader);
|
||||||
if (m_px_range_uniform >= 0) {
|
if (m_px_range_uniform >= 0) {
|
||||||
float shader_px_range = rt.px_range;
|
float shader_px_range = rt.px_range;
|
||||||
// SetShaderValue(
|
SetShaderValue(m_msdf_shader, m_px_range_uniform, &shader_px_range,
|
||||||
// m_msdf_shader, m_px_range_uniform, &shader_px_range,
|
SHADER_UNIFORM_FLOAT);
|
||||||
// SHADER_UNIFORM_FLOAT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned i = 0; i < length; ++i) {
|
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);
|
pen_y_em += hb_to_em(positions[i].y_advance, rt.units_per_em);
|
||||||
}
|
}
|
||||||
|
|
||||||
// EndShaderMode();
|
EndShaderMode();
|
||||||
hb_buffer_destroy(buffer);
|
hb_buffer_destroy(buffer);
|
||||||
|
|
||||||
auto const draw_end = std::chrono::steady_clock::now();
|
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_x = kAtlasPadding;
|
||||||
runtime->pen_y = kAtlasPadding;
|
runtime->pen_y = kAtlasPadding;
|
||||||
runtime->row_height = 0;
|
runtime->row_height = 0;
|
||||||
runtime->px_range = kDefaultPxRange;
|
runtime->px_range = 0.05; // kDefaultPxRange;
|
||||||
runtime->em_scale = kDefaultEmScale;
|
runtime->em_scale = kDefaultEmScale;
|
||||||
runtime->frame_stamp = 0;
|
runtime->frame_stamp = 0;
|
||||||
runtime->units_per_em
|
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