From 61e38a14826de9d5d2b5f899fbae788219dc29e2 Mon Sep 17 00:00:00 2001 From: shweet Date: Mon, 17 Nov 2025 03:15:34 -0500 Subject: [PATCH] Add inset on layers for animations to avoid bleed; change GL settings to avoid stretching pixels if crop larger than texture size --- src/imgui/window/animation_preview.cpp | 13 ++++++++++--- src/resource/texture.cpp | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/imgui/window/animation_preview.cpp b/src/imgui/window/animation_preview.cpp index 5fa6600..353cee6 100644 --- a/src/imgui/window/animation_preview.cpp +++ b/src/imgui/window/animation_preview.cpp @@ -392,13 +392,20 @@ namespace anm2ed::imgui math::percent_to_unit(frame.scale), frame.rotation); auto layerTransform = transform * layerModel; - auto uvMin = frame.crop / vec2(texture.size); - auto uvMax = (frame.crop + frame.size) / vec2(texture.size); - auto vertices = math::uv_vertices_get(uvMin, uvMax); + auto texSize = vec2(texture.size); + if (texSize.x <= 0.0f || texSize.y <= 0.0f) continue; + + auto uvMin = frame.crop / texSize; + auto uvMax = (frame.crop + frame.size) / texSize; vec3 frameColorOffset = frame.colorOffset + colorOffset; vec4 frameTint = frame.tint; frameTint.a = std::max(0.0f, frameTint.a - alphaOffset); + auto inset = vec2(0.5f) / texSize; + uvMin += inset; + uvMax -= inset; + auto vertices = math::uv_vertices_get(uvMin, uvMax); + texture_render(shaderTexture, texture.id, layerTransform, frameTint, frameColorOffset, vertices.data()); auto color = isOnionskin ? vec4(colorOffset, 1.0f - alphaOffset) : color::RED; diff --git a/src/resource/texture.cpp b/src/resource/texture.cpp index 1a2b9fd..3da354a 100644 --- a/src/resource/texture.cpp +++ b/src/resource/texture.cpp @@ -43,8 +43,8 @@ namespace anm2ed::resource glBindTexture(GL_TEXTURE_2D, id); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); glPixelStorei(GL_UNPACK_ALIGNMENT, 1);