From: hgn Date: Mon, 17 Feb 2025 20:04:20 +0000 (+0000) Subject: fix: shader recompile, fix: ui string length count vt codes, change: vg_camera now... X-Git-Url: https://harrygodden.com/git/?a=commitdiff_plain;h=refs%2Fheads%2Fvg3;p=vg.git fix: shader recompile, fix: ui string length count vt codes, change: vg_camera now takes resolution as a required parameter to calculate ratio --- diff --git a/vg_camera.c b/vg_camera.c index 3828645..cb44a56 100644 --- a/vg_camera.c +++ b/vg_camera.c @@ -64,12 +64,10 @@ void vg_camera_update_view( vg_camera *cam ) /* * 3) [fov,nearz,farz] -> projection matrix */ -void vg_camera_update_projection( vg_camera *cam ) +void vg_camera_update_projection( vg_camera *cam, f32 vw, f32 vh ) { m4x4_copy( cam->mtx.p, cam->mtx_prev.p ); - m4x4_projection( cam->mtx.p, cam->fov, - (float)vg.window_x / (float)vg.window_y, - cam->nearz, cam->farz ); + m4x4_projection( cam->mtx.p, cam->fov, (float)vw / (float)vh, cam->nearz, cam->farz ); } /* diff --git a/vg_camera.h b/vg_camera.h index 45d3444..a0846b0 100644 --- a/vg_camera.h +++ b/vg_camera.h @@ -43,7 +43,7 @@ void vg_camera_update_view( vg_camera *cam ); /* * 3) [fov,nearz,farz] -> projection matrix */ -void vg_camera_update_projection( vg_camera *cam ); +void vg_camera_update_projection( vg_camera *cam, f32 vw, f32 vh ); /* * 4) [projection matrix, view matrix] -> previous pv, new pv diff --git a/vg_engine.c b/vg_engine.c index b7fd4c6..6f0d519 100644 --- a/vg_engine.c +++ b/vg_engine.c @@ -239,8 +239,7 @@ static void _vg_process_events(void) if( !w || !h ) { - vg_warn( "Got a invalid framebuffer size: " - "%dx%d... ignoring\n", w, h ); + vg_warn( "Got a invalid framebuffer size: %dx%d... ignoring\n", w, h ); } else { @@ -249,8 +248,9 @@ static void _vg_process_events(void) _vg_magi_area_change( delta ); vg.window_x = w; vg.window_y = h; - + vg_framebuffer_update_sizes(); + vg_framebuffer_resize( vg.window_x, vg.window_y ); } } else if( event.window.event == SDL_WINDOWEVENT_CLOSE ) diff --git a/vg_loader.c b/vg_loader.c index b49ea12..9908689 100644 --- a/vg_loader.c +++ b/vg_loader.c @@ -141,7 +141,7 @@ void vg_loader_render_ring( f32 opacity ) opacity *= opacity; glUseProgram( _shader_loader.id ); - glUniform1f( glGetUniformLocation( _shader_loader.id, "uTime" ), vg.time ); + glUniform1f( glGetUniformLocation( _shader_loader.id, "uTime" ), vg.time_real ); f32 ratio = (f32)vg.window_x / (f32)vg.window_y; glUniform1f( glGetUniformLocation( _shader_loader.id, "uRatio"), ratio ); glUniform1f( glGetUniformLocation( _shader_loader.id, "uOpacity"), opacity ); diff --git a/vg_shader.c b/vg_shader.c index bafab34..3441207 100644 --- a/vg_shader.c +++ b/vg_shader.c @@ -218,6 +218,10 @@ int vg_shaders_live_recompile( int argc, const char *argv[] ) vg_recompile_shader( shader ); } +#ifdef VG_CUSTOM_SHADERS + vg_auto_shader_link(); +#endif + return 0; } diff --git a/vg_ui/imgui.c b/vg_ui/imgui.c index 1a4ea5b..dbcbe5e 100644 --- a/vg_ui/imgui.c +++ b/vg_ui/imgui.c @@ -335,7 +335,21 @@ ui_px ui_text_line_width( ui_context *ctx, const char *str ) const char *_c = str; u8 c; - while( (c = *(_c ++)) ){ + while( (c = *(_c ++)) ) + { + /* skip vt colour codes */ + if( c == '\x1B' ) + { + while( (c = *(_c ++)) ) + { + if( c == 'm' ) + break; + } + + if( c == 0 ) break; + else continue; + } + if( c >= 32 ) length ++; else if( c == '\n' ) break; } diff --git a/vg_ui/imgui.h b/vg_ui/imgui.h index 8672cf4..8b85392 100644 --- a/vg_ui/imgui.h +++ b/vg_ui/imgui.h @@ -316,10 +316,8 @@ enum ui_button_state ui_colourbutton_text( ui_rect rect, const char *string, ui_px scale, enum ui_scheme_colour colour ); -enum ui_button_state ui_button_text( ui_context *ctx, ui_rect rect, - const char *string, ui_px scale ); -enum ui_button_state ui_button( ui_context *ctx, - ui_rect inout_panel, const char *string ); +enum ui_button_state ui_button_text( ui_context *ctx, ui_rect rect, const char *string, ui_px scale ); +enum ui_button_state ui_button( ui_context *ctx, ui_rect inout_panel, const char *string ); void ui_postrender( ui_context *ctx, f32 delta_time ); enum ui_button_state ui_checkbox_base( ui_context *ctx, ui_rect box, i32 *data );