From 52584f888cdd22edcc011e677ecdec53b8bfb554 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Fri, 10 Jan 2025 16:14:59 -0500 Subject: [PATCH] fixing some normalized space calculation issues I need to review the convention I'm using for the "view" or at least how I interpret these coordinate spaces so its inutitive for the interface. At the end of the day, the draw_list should be in normalized space, however how it gets digested to that state needs to be better documented or made more explicit in its transformation from the usual user calls. --- examples/sokol_demo/sokol_demo.odin | 18 ++++++++++++++---- vefontcache/vefontcache.odin | 18 ++++++++++++------ 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/examples/sokol_demo/sokol_demo.odin b/examples/sokol_demo/sokol_demo.odin index 6448a3c..7303e69 100644 --- a/examples/sokol_demo/sokol_demo.odin +++ b/examples/sokol_demo/sokol_demo.odin @@ -154,8 +154,7 @@ draw_text_string_pos_norm :: proc( content : string, font : Font_ID, size : f32, { color_norm := normalize_rgba8(color) def := demo_ctx.font_ids[ font.label ] - - size := size > 2.0 ? size : f32(def.default_size) + size := size > 2.0 ? size : f32(def.default_size) ve.draw_text_normalized_space( & demo_ctx.ve_ctx, def.ve_id, @@ -163,7 +162,7 @@ draw_text_string_pos_norm :: proc( content : string, font : Font_ID, size : f32, color_norm, demo_ctx.screen_size, pos, - scale * 1 / demo_ctx.screen_size, + scale, 1.0, content ) @@ -257,7 +256,18 @@ init :: proc "c" () case .DUMMY: fmt.println(">> using dummy backend") } - ve.startup( & demo_ctx.ve_ctx, .STB_TrueType, allocator = context.allocator ) + glyph_draw_opts := ve.Init_Glyph_Draw_Params_Default + glyph_draw_opts.snap_glyph_height = false + + shaper_opts := ve.Init_Shaper_Params_Default + shaper_opts.snap_glyph_position = false + + ve.startup( & demo_ctx.ve_ctx, .STB_TrueType, allocator = context.allocator, + glyph_draw_params = glyph_draw_opts, + shaper_params = shaper_opts, + px_scalar = 1.5, + alpha_sharpen = 0.1, + ) ve_sokol.setup_gfx_objects( & demo_ctx.render_ctx, & demo_ctx.ve_ctx, vert_cap = 1024 * 1024, index_cap = 1024 * 1024 ) error : mem.Allocator_Error diff --git a/vefontcache/vefontcache.odin b/vefontcache/vefontcache.odin index 100b63a..3f22030 100644 --- a/vefontcache/vefontcache.odin +++ b/vefontcache/vefontcache.odin @@ -686,7 +686,7 @@ draw_text_shape_normalized_space :: #force_inline proc( ctx : ^Context, font : Font_ID, px_size : f32, colour : RGBAN, - view : Vec2, + view : Vec2, // Screen position : Vec2, scale : Vec2, zoom : f32, // TODO(Ed): Implement zoom support @@ -702,10 +702,13 @@ draw_text_shape_normalized_space :: #force_inline proc( ctx : ^Context, entry := ctx.entries[ font ] adjusted_colour := colour - adjusted_colour.a = 1.0 + ctx.alpha_sharpen + adjusted_colour.a += ctx.alpha_sharpen + + view_norm := 1 / view + scale_norm := scale * view_norm target_px_size := px_size * ctx.px_scalar - target_scale := scale * (1 / ctx.px_scalar) + target_scale := scale_norm * (1 / ctx.px_scalar) target_font_scale := parser_scale( entry.parser_info, target_px_size ) ctx.cursor_pos = generate_shape_draw_list( & ctx.draw_list, shape, & ctx.atlas, & ctx.glyph_buffer, @@ -743,12 +746,15 @@ draw_text_normalized_space :: proc( ctx : ^Context, adjusted_position := get_snapped_position( position, view ) - adjusted_colour := colour - adjusted_colour.a = 1.0 + ctx.alpha_sharpen + adjusted_colour := colour + adjusted_colour.a += ctx.alpha_sharpen + + view_norm := 1 / view + scale_norm := scale * view_norm // Does nothing when px_scalar is 1.0 target_px_size := px_size * ctx.px_scalar - target_scale := scale * (1 / ctx.px_scalar) + target_scale := scale_norm * (1 / ctx.px_scalar) target_font_scale := parser_scale( entry.parser_info, target_px_size ) shape := shaper_shape_text_cached( text_utf8, & ctx.shaper_ctx, & ctx.shape_cache, ctx.atlas, vec2(ctx.glyph_buffer.size),