Skip to content

Commit 4d2cb52

Browse files
committed
D3D,OGL: fix sprite origin breaking pixel precise position
1 parent 26390b3 commit 4d2cb52

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

Engine/gfx/ali3dogl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,9 +1479,9 @@ void OGLGraphicsDriver::RenderTexture(OGLBitmap *bmpToDraw, int draw_x, int draw
14791479
heightToScale = -heightToScale;
14801480
thisY += height;
14811481
}
1482-
// Apply sprite origin
1483-
thisX -= (abs(widthToScale) - 1.f) * bmpToDraw->GetOrigin().X;
1484-
thisY -= (abs(heightToScale) - 1.f) * bmpToDraw->GetOrigin().Y;
1482+
// Apply sprite origin, rounded to keep pixel precision
1483+
thisX -= std::roundf((abs(widthToScale) - 1.f) * bmpToDraw->GetOrigin().X);
1484+
thisY -= std::roundf((abs(heightToScale) - 1.f) * bmpToDraw->GetOrigin().Y);
14851485
// Center inside a rendering rect
14861486
// FIXME: this should be a part of a projection matrix, afaik
14871487
thisX = (-(rend_sz.Width / 2.0f)) + thisX;

Engine/platform/windows/gfx/ali3dd3d.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,12 +1506,9 @@ void D3DGraphicsDriver::RenderTexture(D3DBitmap *bmpToDraw, int draw_x, int draw
15061506
heightToScale = -heightToScale;
15071507
thisY += height;
15081508
}
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;
1509+
// Apply sprite origin, rounded to keep pixel precision
1510+
thisX -= std::roundf((abs(widthToScale) - 1.f) * bmpToDraw->GetOrigin().X);
1511+
thisY -= std::roundf((abs(heightToScale) - 1.f) * bmpToDraw->GetOrigin().Y);
15151512
// Center inside a rendering rect
15161513
// FIXME: this should be a part of a projection matrix, afaik
15171514
thisX = (-(rend_sz.Width / 2.0f)) + thisX;

0 commit comments

Comments
 (0)