Skip to content

Commit

Permalink
Fixed bug 2421 for D3D9 - SDL_RenderCopyEx off by one when rotating b…
Browse files Browse the repository at this point in the history
…y 90 and -90

Nader Golbaz

Updated patch for direct3d renderers
  • Loading branch information
slouken committed Nov 6, 2016
1 parent d767a45 commit 4ed4997
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions src/render/direct3d/SDL_render_d3d.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 4ed4997

Please sign in to comment.