Skip to content

Commit cf65871

Browse files
committed
D3D,OGL: fix sprite origin breaking pixel precise position
1 parent efef1a2 commit cf65871

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

Engine/gfx/ali3dogl.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#if AGS_HAS_OPENGL
1717
#include "gfx/ali3dogl.h"
1818
#include <algorithm>
19+
#include <cmath>
1920
#include <stack>
2021
#include <SDL.h>
2122
#include "ac/sys_events.h"
@@ -1479,9 +1480,9 @@ void OGLGraphicsDriver::RenderTexture(OGLBitmap *bmpToDraw, int draw_x, int draw
14791480
heightToScale = -heightToScale;
14801481
thisY += height;
14811482
}
1482-
// Apply sprite origin
1483-
thisX -= (abs(widthToScale) - 1.f) * bmpToDraw->GetOrigin().X;
1484-
thisY -= (abs(heightToScale) - 1.f) * bmpToDraw->GetOrigin().Y;
1483+
// Apply sprite origin, rounded to keep pixel precision
1484+
thisX -= std::roundf((abs(widthToScale) - 1.f) * bmpToDraw->GetOrigin().X);
1485+
thisY -= std::roundf((abs(heightToScale) - 1.f) * bmpToDraw->GetOrigin().Y);
14851486
// Center inside a rendering rect
14861487
// FIXME: this should be a part of a projection matrix, afaik
14871488
thisX = (-(rend_sz.Width / 2.0f)) + thisX;

Engine/platform/windows/gfx/ali3dd3d.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#define NOMINMAX
1818
#include "platform/windows/gfx/ali3dd3d.h"
1919
#include <algorithm>
20+
#include <cmath>
2021
#include <stack>
2122
#include <SDL.h>
2223
#include <glm/ext.hpp>
@@ -1506,12 +1507,9 @@ void D3DGraphicsDriver::RenderTexture(D3DBitmap *bmpToDraw, int draw_x, int draw
15061507
heightToScale = -heightToScale;
15071508
thisY += height;
15081509
}
1509-
// Apply sprite origin
1510-
// CHECKME: applying -1 to width conflicts with _pixelRenderXOffset, it seems;
1511-
// (_pixelRenderXOffset * 2.f) factor was found by experiment, comparing with
1512-
// other renderers, using cases with middle and rightmost origin.
1513-
thisX -= (abs(widthToScale) - _pixelRenderXOffset * 2.f) * bmpToDraw->GetOrigin().X;
1514-
thisY -= (abs(heightToScale) - 1.f) * bmpToDraw->GetOrigin().Y;
1510+
// Apply sprite origin, rounded to keep pixel precision
1511+
thisX -= std::roundf((abs(widthToScale) - 1.f) * bmpToDraw->GetOrigin().X);
1512+
thisY -= std::roundf((abs(heightToScale) - 1.f) * bmpToDraw->GetOrigin().Y);
15151513
// Center inside a rendering rect
15161514
// FIXME: this should be a part of a projection matrix, afaik
15171515
thisX = (-(rend_sz.Width / 2.0f)) + thisX;

0 commit comments

Comments
 (0)