Commit 7f262312 authored by Sam Lantinga's avatar Sam Lantinga

[SDL] Bad math in SDL_RenderCopy

Mason Wheeler to sdl

When I tried to render an image using something other than NULL for srcrect, it got horribly distorted.  I traced it down to the fact that the math in the rectangle adjustments performed just before the call to renderer->RenderCopy is written inside out.  It should look like this:

       if (dstrect->w != real_dstrect.w) {
           int deltax = (dstrect->x - real_dstrect.x);
           int deltaw = (dstrect->w - real_dstrect.w);
           real_srcrect.x += (deltax * real_srcrect.w) / dstrect->w;
           real_srcrect.w += (deltaw * real_srcrect.w) / dstrect->w;
       }
       if (dstrect->h != real_dstrect.h) {
           int deltay = (dstrect->y - real_dstrect.y);
           int deltah = (dstrect->h - real_dstrect.h);
           real_srcrect.y += (deltay * real_srcrect.h) / dstrect->h;
           real_srcrect.h += (deltah * real_srcrect.h) / dstrect->h;

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403957
parent b330607c
...@@ -2463,14 +2463,14 @@ SDL_RenderCopy(SDL_TextureID textureID, const SDL_Rect * srcrect, ...@@ -2463,14 +2463,14 @@ SDL_RenderCopy(SDL_TextureID textureID, const SDL_Rect * srcrect,
if (dstrect->w != real_dstrect.w) { if (dstrect->w != real_dstrect.w) {
int deltax = (real_dstrect.x - dstrect->x); int deltax = (real_dstrect.x - dstrect->x);
int deltaw = (real_dstrect.w - dstrect->w); int deltaw = (real_dstrect.w - dstrect->w);
real_srcrect.x += (deltax * dstrect->w) / real_srcrect.w; real_srcrect.x += (deltax * real_srcrect.w) / dstrect->w;
real_srcrect.w += (deltaw * dstrect->w) / real_srcrect.w; real_srcrect.w += (deltaw * real_srcrect.w) / dstrect->w;
} }
if (dstrect->h != real_dstrect.h) { if (dstrect->h != real_dstrect.h) {
int deltay = (real_dstrect.y - dstrect->y); int deltay = (real_dstrect.y - dstrect->y);
int deltah = (real_dstrect.h - dstrect->h); int deltah = (real_dstrect.h - dstrect->h);
real_srcrect.y += (deltay * dstrect->h) / real_srcrect.h; real_srcrect.y += (deltay * real_srcrect.h) / dstrect->h;
real_srcrect.h += (deltah * dstrect->h) / real_srcrect.h; real_srcrect.h += (deltah * real_srcrect.h) / dstrect->h;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment