Fixed bug 2421 for D3D9 - SDL_RenderCopyEx off by one when rotating by 90 and -90 Nader Golbaz Updated patch for direct3d renderers
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
diff --git a/src/render/direct3d/SDL_render_d3d.c b/src/render/direct3d/SDL_render_d3d.c
index 151dbbf..12ede94 100644
--- a/src/render/direct3d/SDL_render_d3d.c
+++ b/src/render/direct3d/SDL_render_d3d.c
@@ -1723,29 +1723,27 @@ D3D_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
centerx = center->x;
centery = center->y;
- if (flip & SDL_FLIP_HORIZONTAL) {
- minx = dstrect->w - centerx - 0.5f;
- maxx = -centerx - 0.5f;
- }
- else {
- minx = -centerx - 0.5f;
- maxx = dstrect->w - centerx - 0.5f;
- }
-
- if (flip & SDL_FLIP_VERTICAL) {
- miny = dstrect->h - centery - 0.5f;
- maxy = -centery - 0.5f;
- }
- else {
- miny = -centery - 0.5f;
- maxy = dstrect->h - centery - 0.5f;
- }
+ minx = -centerx;
+ maxx = dstrect->w - centerx;
+ miny = -centery;
+ maxy = dstrect->h - centery;
minu = (float) srcrect->x / texture->w;
maxu = (float) (srcrect->x + srcrect->w) / texture->w;
minv = (float) srcrect->y / texture->h;
maxv = (float) (srcrect->y + srcrect->h) / texture->h;
+ if (flip & SDL_FLIP_HORIZONTAL) {
+ float tmp = maxu;
+ maxu = minu;
+ minu = tmp;
+ }
+ if (flip & SDL_FLIP_VERTICAL) {
+ float tmp = maxv;
+ maxv = minv;
+ minv = tmp;
+ }
+
color = D3DCOLOR_ARGB(texture->a, texture->r, texture->g, texture->b);
vertices[0].x = minx;
@@ -1781,8 +1779,7 @@ D3D_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
/* Rotate and translate */
modelMatrix = MatrixMultiply(
MatrixRotationZ((float)(M_PI * (float) angle / 180.0f)),
- MatrixTranslation(dstrect->x + center->x, dstrect->y + center->y, 0)
-);
+ MatrixTranslation(dstrect->x + center->x - 0.5f, dstrect->y + center->y - 0.5f, 0));
IDirect3DDevice9_SetTransform(data->device, D3DTS_VIEW, (D3DMATRIX*)&modelMatrix);
D3D_UpdateTextureScaleMode(data, texturedata, 0);