Update J2D.cpp
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 2m11s

Fix a case that would sometimes cause Render Targets to appear strange due to being drawn at a sub-pixel position.
This commit is contained in:
2025-01-28 19:06:17 -05:00
parent 8cb470ad1c
commit d60620ef7c

View File

@@ -412,7 +412,8 @@ void JGL::J2D::DrawSprite(const JGL::RenderTarget& rt, const Vector2& position,
if (rt.OwnsTexture())
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
JGL::J2D::DrawPartialSprite(*rt.GetJGLTexture(), position, {0, 0}, Vector2(rt.GetDimensions()), rad_rotation, origin, scale, color, d);
auto r_position = Vector2(Math::Floor(position.x), Math::Floor(position.y));
JGL::J2D::DrawPartialSprite(*rt.GetJGLTexture(), r_position, {0, 0}, Vector2(rt.GetDimensions()), rad_rotation, origin, scale, color, d);
if (rt.OwnsTexture())
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -546,7 +547,10 @@ void JGL::J2D::DrawPartialRenderTarget(const JGL::RenderTarget& rt, const Vector
if (rt.OwnsTexture())
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
JGL::J2D::DrawPartialSprite(*rt.GetJGLTexture(), position, sub_texture_position, sub_texture_size, rad_rotation, origin, scale, color, d);
auto r_position = Vector2(Math::Floor(position.x), Math::Floor(position.y));
auto r_sub_texture_position = Vector2(Math::Floor(sub_texture_position.x), Math::Floor(sub_texture_position.y));
JGL::J2D::DrawPartialSprite(*rt.GetJGLTexture(), r_position, r_sub_texture_position, sub_texture_size, rad_rotation, origin, scale, color, d);
if (rt.OwnsTexture())
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);