From 15839ae6ca94b319e4260c29f4cffaca02214623 Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Sat, 23 Dec 2023 22:24:59 +0800 Subject: [PATCH] ttf_outline: rectangular textures must include all bytes Previously, the texture was truncated, which caused spurious pixels to appear in the last row(s) of the texture. --- dejavusansmono.data | Bin 34613 -> 34712 bytes dejavusansmono_mono.data | Bin 5868 -> 6040 bytes example/font_outline.cpp | 58 +++++++++++++++++++++++-- example/font_outline_punch_through.cpp | 6 +-- tools/ttf_outline.cpp | 4 +- 5 files changed, 60 insertions(+), 8 deletions(-) diff --git a/dejavusansmono.data b/dejavusansmono.data index aca0123e0b5a0714f692fd12e8ed050a66355e2c..e61fec3d6890212c74d5446e447319b8d70f9490 100644 GIT binary patch delta 81 zcmdnm$26m#Nl1Z#fgypxfwO_3fq{V$$Z6Opq}(nAWB@_M|Nl7^S`ao%;QFUOZuQAb Y_HR}Y@cIAW1|&S=KNxUKcC3^H09W}MRsaA1 delta 29 kcmbQy&$P9VNl1Z#fgypxfwO_3fq{XMfnjd_Mj_>P0BAi1)Bpeg diff --git a/dejavusansmono_mono.data b/dejavusansmono_mono.data index 6e746966bc9d46597b0241974fa9735652cd2eaf..7e234c583bdd9ae0e5fd97a2700c1249a8f2a50e 100644 GIT binary patch delta 201 zcmaE(J40Vcfq{V`fx&@OfT4kbff2|N*eG;Mto}c{T|+&P2LcZsJox*cy`Di1!e#jX z|34!`!*>M#{(lCBhR1OA|K;r&7!DkK_!eXw5c~m|`=Ft?hZ(~E-^}>ue>sCX4^$p# f+@JsU417EgX@=(ijJkjRvokQj1Q=_eGB_vzH;yZ( delta 27 icmbQC|3+6xfq{V`fx&@OfT4kbfsuhBgny&ZEinL1!Ubah diff --git a/example/font_outline.cpp b/example/font_outline.cpp index 8feebfe..9535d53 100644 --- a/example/font_outline.cpp +++ b/example/font_outline.cpp @@ -39,8 +39,8 @@ const struct vertex strip_vertices[4] = { constexpr uint32_t strip_length = (sizeof (strip_vertices)) / (sizeof (struct vertex)); uint32_t transform(ta_parameter_writer& parameter, - const uint32_t first_char_code, const uint32_t texture_width, uint32_t texture_height, + const uint32_t first_char_code, const glyph * glyphs, const char * s, const uint32_t len, const uint32_t y_offset) @@ -110,6 +110,53 @@ uint32_t transform(ta_parameter_writer& parameter, return parameter.offset; } +uint32_t transform2(ta_parameter_writer& parameter, + const uint32_t texture_width, uint32_t texture_height) +{ + uint32_t texture_address = (offsetof (struct texture_memory_alloc, texture)); + + auto polygon = global_polygon_type_0(texture_address); + polygon.parameter_control_word = para_control::para_type::polygon_or_modifier_volume + | para_control::list_type::opaque + | obj_control::col_type::packed_color + | obj_control::texture; + + polygon.tsp_instruction_word = tsp_instruction_word::src_alpha_instr::one + | tsp_instruction_word::dst_alpha_instr::zero + | tsp_instruction_word::fog_control::no_fog + | tsp_instruction_word::texture_u_size::from_int(texture_width) + | tsp_instruction_word::texture_v_size::from_int(texture_height); + + polygon.texture_control_word = texture_control_word::pixel_format::_8bpp_palette + | texture_control_word::scan_order::twiddled + | texture_control_word::texture_address(texture_address / 8); + parameter.append() = polygon; + + for (uint32_t i = 0; i < strip_length; i++) { + bool end_of_strip = i == strip_length - 1; + + float x = strip_vertices[i].x; + float y = strip_vertices[i].y; + float z = strip_vertices[i].z; + + x *= 128.f; + y *= 256.f; + x += 50.f; + y += 50.f; + z = 1.f / (z + 9.f); + + float u = strip_vertices[i].u; + float v = strip_vertices[i].v; + + parameter.append() = + vertex_polygon_type_3(x, y, z, + u, v, + 0x00000000, // base_color + end_of_strip); + } + + return parameter.offset; +} void init_texture_memory(const struct opb_size& opb_size) { @@ -219,19 +266,24 @@ void main() auto parameter = ta_parameter_writer(ta_parameter_buf); + transform2(parameter, + font->texture_width, font->texture_height); + + /* transform(parameter, - font->first_char_code, font->texture_width, font->texture_height, + font->first_char_code, glyphs, ana, 17, font->glyph_height * 0); transform(parameter, - font->first_char_code, font->texture_width, font->texture_height, + font->first_char_code, glyphs, cabal, 26, font->glyph_height * 1); + */ parameter.append() = global_end_of_list(); diff --git a/example/font_outline_punch_through.cpp b/example/font_outline_punch_through.cpp index cb119d4..30f1a05 100644 --- a/example/font_outline_punch_through.cpp +++ b/example/font_outline_punch_through.cpp @@ -39,8 +39,8 @@ const struct vertex strip_vertices[4] = { constexpr uint32_t strip_length = (sizeof (strip_vertices)) / (sizeof (struct vertex)); uint32_t transform(ta_parameter_writer& parameter, - const uint32_t first_char_code, const uint32_t texture_width, uint32_t texture_height, + const uint32_t first_char_code, const glyph * glyphs, const char * s, const uint32_t len, const uint32_t y_offset) @@ -230,15 +230,15 @@ void main() auto parameter = ta_parameter_writer(ta_parameter_buf); transform(parameter, - font->first_char_code, font->texture_width, font->texture_height, + font->first_char_code, glyphs, ana, 17, font->glyph_height * 0); transform(parameter, - font->first_char_code, font->texture_width, font->texture_height, + font->first_char_code, glyphs, cabal, 26, font->glyph_height * 1); diff --git a/tools/ttf_outline.cpp b/tools/ttf_outline.cpp index 2327b74..ba5c042 100644 --- a/tools/ttf_outline.cpp +++ b/tools/ttf_outline.cpp @@ -279,10 +279,10 @@ int main(int argc, char *argv[]) uint32_t texture_size; if (monochrome) { texture_stride = window_curve_ix.window.width / 8; - texture_size = byteswap((window_curve_ix.max_z_curve_ix / 8) + 1); + texture_size = window_curve_ix.window.width * window_curve_ix.window.height / 8; } else { texture_stride = window_curve_ix.window.width; - texture_size = byteswap((window_curve_ix.max_z_curve_ix / 1) + 1); + texture_size = window_curve_ix.window.width * window_curve_ix.window.height; } font font;