Fixed bug 2421 for D3D9 - SDL_RenderCopyEx off by one when rotating by 90 and -90
authorSam Lantinga <slouken@libsdl.org>
Sun, 06 Nov 2016 08:42:46 -0800
changeset 1058414333c920cd7
parent 10583 974f8ebcb819
child 10585 96c2a6560b52
Fixed bug 2421 for D3D9 - SDL_RenderCopyEx off by one when rotating by 90 and -90

Nader Golbaz

Updated patch for direct3d renderers
src/render/direct3d/SDL_render_d3d.c
     1.1 --- a/src/render/direct3d/SDL_render_d3d.c	Sun Nov 06 08:34:27 2016 -0800
     1.2 +++ b/src/render/direct3d/SDL_render_d3d.c	Sun Nov 06 08:42:46 2016 -0800
     1.3 @@ -1723,29 +1723,27 @@
     1.4      centerx = center->x;
     1.5      centery = center->y;
     1.6  
     1.7 -    if (flip & SDL_FLIP_HORIZONTAL) {
     1.8 -        minx = dstrect->w - centerx - 0.5f;
     1.9 -        maxx = -centerx - 0.5f;
    1.10 -    }
    1.11 -    else {
    1.12 -        minx = -centerx - 0.5f;
    1.13 -        maxx = dstrect->w - centerx - 0.5f;
    1.14 -    }
    1.15 -
    1.16 -    if (flip & SDL_FLIP_VERTICAL) {
    1.17 -        miny = dstrect->h - centery - 0.5f;
    1.18 -        maxy = -centery - 0.5f;
    1.19 -    }
    1.20 -    else {
    1.21 -        miny = -centery - 0.5f;
    1.22 -        maxy = dstrect->h - centery - 0.5f;
    1.23 -    }
    1.24 +    minx = -centerx;
    1.25 +    maxx = dstrect->w - centerx;
    1.26 +    miny = -centery;
    1.27 +    maxy = dstrect->h - centery;
    1.28  
    1.29      minu = (float) srcrect->x / texture->w;
    1.30      maxu = (float) (srcrect->x + srcrect->w) / texture->w;
    1.31      minv = (float) srcrect->y / texture->h;
    1.32      maxv = (float) (srcrect->y + srcrect->h) / texture->h;
    1.33  
    1.34 +    if (flip & SDL_FLIP_HORIZONTAL) {
    1.35 +        float tmp = maxu;
    1.36 +        maxu = minu;
    1.37 +        minu = tmp;
    1.38 +    }
    1.39 +    if (flip & SDL_FLIP_VERTICAL) {
    1.40 +        float tmp = maxv;
    1.41 +        maxv = minv;
    1.42 +        minv = tmp;
    1.43 +    }
    1.44 +
    1.45      color = D3DCOLOR_ARGB(texture->a, texture->r, texture->g, texture->b);
    1.46  
    1.47      vertices[0].x = minx;
    1.48 @@ -1781,8 +1779,7 @@
    1.49      /* Rotate and translate */
    1.50      modelMatrix = MatrixMultiply(
    1.51              MatrixRotationZ((float)(M_PI * (float) angle / 180.0f)),
    1.52 -            MatrixTranslation(dstrect->x + center->x, dstrect->y + center->y, 0)
    1.53 -);
    1.54 +            MatrixTranslation(dstrect->x + center->x - 0.5f, dstrect->y + center->y - 0.5f, 0));
    1.55      IDirect3DDevice9_SetTransform(data->device, D3DTS_VIEW, (D3DMATRIX*)&modelMatrix);
    1.56  
    1.57      D3D_UpdateTextureScaleMode(data, texturedata, 0);