comparison src/video/SDL_video.c @ 3333:b334b4f7dfa0

[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;
author Sam Lantinga <slouken@libsdl.org>
date Sat, 03 Oct 2009 16:23:16 +0000
parents f085091f74cd
children 64a60c5d502e
comparison
equal deleted inserted replaced
3332:da1cb54d74ef 3333:b334b4f7dfa0
2461 } 2461 }
2462 /* Clip srcrect by the same amount as dstrect was clipped */ 2462 /* Clip srcrect by the same amount as dstrect was clipped */
2463 if (dstrect->w != real_dstrect.w) { 2463 if (dstrect->w != real_dstrect.w) {
2464 int deltax = (real_dstrect.x - dstrect->x); 2464 int deltax = (real_dstrect.x - dstrect->x);
2465 int deltaw = (real_dstrect.w - dstrect->w); 2465 int deltaw = (real_dstrect.w - dstrect->w);
2466 real_srcrect.x += (deltax * dstrect->w) / real_srcrect.w; 2466 real_srcrect.x += (deltax * real_srcrect.w) / dstrect->w;
2467 real_srcrect.w += (deltaw * dstrect->w) / real_srcrect.w; 2467 real_srcrect.w += (deltaw * real_srcrect.w) / dstrect->w;
2468 } 2468 }
2469 if (dstrect->h != real_dstrect.h) { 2469 if (dstrect->h != real_dstrect.h) {
2470 int deltay = (real_dstrect.y - dstrect->y); 2470 int deltay = (real_dstrect.y - dstrect->y);
2471 int deltah = (real_dstrect.h - dstrect->h); 2471 int deltah = (real_dstrect.h - dstrect->h);
2472 real_srcrect.y += (deltay * dstrect->h) / real_srcrect.h; 2472 real_srcrect.y += (deltay * real_srcrect.h) / dstrect->h;
2473 real_srcrect.h += (deltah * dstrect->h) / real_srcrect.h; 2473 real_srcrect.h += (deltah * real_srcrect.h) / dstrect->h;
2474 } 2474 }
2475 } 2475 }
2476 2476
2477 return renderer->RenderCopy(renderer, texture, &real_srcrect, 2477 return renderer->RenderCopy(renderer, texture, &real_srcrect,
2478 &real_dstrect); 2478 &real_dstrect);