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.
This commit is contained in:
2025-01-10 16:14:59 -05:00
parent 91e8af8839
commit 52584f888c
2 changed files with 26 additions and 10 deletions

View File

@@ -154,7 +154,6 @@ 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)
ve.draw_text_normalized_space( & demo_ctx.ve_ctx,
@@ -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

View File

@@ -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,
@@ -744,11 +747,14 @@ 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.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),