summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2025-02-05 19:09:10 -0500
committerJonathan Bradley <jcb@pikum.xyz>2025-02-05 19:09:10 -0500
commita9fb380f9d0b53cde554b265d9c6b66d26183c38 (patch)
tree8ea3648c497d4a3ac8ce2f6dafa2beca324e7249 /editor
parent61e179f9580c985cb5ca80ea732fc7572d31c489 (diff)
pke: mtsdf displays, bypass fg/bg not working
Diffstat (limited to 'editor')
-rw-r--r--editor/editor.cpp23
1 files changed, 15 insertions, 8 deletions
diff --git a/editor/editor.cpp b/editor/editor.cpp
index c0eafcb..4ce15e1 100644
--- a/editor/editor.cpp
+++ b/editor/editor.cpp
@@ -721,6 +721,7 @@ int SortFontGlyphChar(const void *a, const void *b) {
void GenerateMTSDF(const Asset *a) {
assert(PK_HAS_FLAG(a->type, PKE_ASSET_TYPE_FONT));
+ glm::ivec4 bounds;
NULL_CHAR_ARR(path_txtr, 128);
NULL_CHAR_ARR(path_glyphs, 128);
std::error_code e;
@@ -745,7 +746,7 @@ void GenerateMTSDF(const Asset *a) {
// Apply MSDF edge coloring. See edge-coloring.h for other coloring strategies.
const double maxCornerAngle = 3.0;
for (msdf_atlas::GlyphGeometry &glyph : glyphs)
- glyph.edgeColoring(&msdfgen::edgeColoringInkTrap, maxCornerAngle, 0);
+ glyph.edgeColoring(&msdfgen::edgeColoringByDistance, maxCornerAngle, 0);
// TightAtlasPacker class computes the layout of the atlas.
msdf_atlas::TightAtlasPacker packer;
// Set atlas parameters:
@@ -770,9 +771,9 @@ void GenerateMTSDF(const Asset *a) {
// For example, a custom atlas storage class that stores it in VRAM can be used.
> generator(width, height);
// GeneratorAttributes can be modified to change the generator's default settings.
- msdf_atlas::GeneratorAttributes attributes;
- generator.setAttributes(attributes);
- // generator.setThreadCount(4);
+ // msdf_atlas::GeneratorAttributes attributes{};
+ // generator.setAttributes(attributes);
+ generator.setThreadCount(31); // TODO engine should know this
// Generate atlas bitmap
generator.generate(glyphs.data(), glyphs.size());
// The atlas bitmap can now be retrieved via atlasStorage as a BitmapConstRef.
@@ -781,17 +782,23 @@ void GenerateMTSDF(const Asset *a) {
msdf_atlas::saveImage<4>(storage, msdf_atlas::ImageFormat::PNG, path_txtr, msdf_atlas::YDirection::TOP_DOWN);
ah_image = AM_Register(path_txtr, PKE_ASSET_TYPE_UNSET);
- auto f = fopen(path_glyphs, "w+");
- pk_arr arr_glyphs = {};
- arr_glyphs.alignment = 8;
+ pk_arr arr_glyphs{};
+ arr_glyphs.alignment = alignof(FontGlyphChar);
arr_glyphs.stride = sizeof(FontGlyphChar);
pk_arr_resize(&arr_glyphs, glyphs.size());
FontGlyphChar *arr = reinterpret_cast<FontGlyphChar *>(arr_glyphs.data);
for (uint64_t i = 0; i < glyphs.size(); ++i) {
arr[i].unicode = glyphs[i].getCodepoint();
- glyphs[i].getBoxRect(arr[i].bounds.x, arr[i].bounds.y, arr[i].bounds.z, arr[i].bounds.a);
+
+ glyphs[i].getBoxRect(bounds.x, bounds.y, bounds.z, bounds.a);
+ // library counts up from the bottom of the image to the bottom of the glyph
+ bounds.y = height - (bounds.y + bounds.a);
+ arr[i].sprite_region_min = glm::vec2(bounds.x, bounds.y);
+ arr[i].sprite_region_max = glm::vec2(bounds.x, bounds.y) + glm::vec2(bounds.z, bounds.a);
}
qsort(arr_glyphs.data, arr_glyphs.next, arr_glyphs.stride, SortFontGlyphChar);
+
+ auto f = fopen(path_glyphs, "w+");
fwrite(arr_glyphs.data, arr_glyphs.stride, arr_glyphs.next, f);
fclose(f);
ah_glyphs = AM_Register(path_glyphs, PKE_ASSET_TYPE_UNSET);