author Sam Lantinga <>
Thu, 01 Aug 2013 09:15:36 -0700
changeset 7563 c128ed448c30
parent 7359 96ac247b672e
child 7599 bd0c15431dc9
permissions -rw-r--r--
Fixed bug 1968 - SDL_RenderCopy stretch loses proportion on viewport boundaries for 3D renderers


SDL_RenderCopy clips dstrect against the viewport. Then it adjusts the
srcrect by "appropriate" amount of pixels. This amount is actually
wrong, quite a lot, because of the rounding errors introduced in the "*
factor / factor" scale.

real_srcrect.x += (deltax * real_srcrect.w) / dstrect->w;
real_srcrect.w += (deltaw * real_srcrect.w) / dstrect->w;

For example:

I have a 32 x 32 srcrect and a 64 x 64 dstrect. So far the
stretching is done perfectly, by a factor of 2.

Now, consider dstrect being clipped against the viewport, so it becomes
56 x 64. Now, the factor becomes 1.75 ! The adjustment to "srcrect"
can't handle this, cause srcrect is in integers.

And thus we now have incorrect mapping, with dstrect not being in the
right proportion to srcrect.

The problem is most evident when upscaling stuff, like displaying a 8x8
texture with a zoom of 64 or more, and moving it beyond the corners of
the screen. It *looks* really really bad.

Note: RenderCopyEX does no such clipping, and is right to do so. The fix would be to remove any such clipping from RenderCopy too. And then fix the software renderer, because it has the same fault, independently of RenderCopy.

[attached patch]
this leaves Software Renderer buggy, as it does it's own clipping later on
     2                          Simple DirectMedia Layer
     4                                   (SDL)
     6                                 Version 2.0
     8 ---
    11 Simple DirectMedia Layer is a cross-platform development library designed
    12 to provide low level access to audio, keyboard, mouse, joystick, and graphics
    13 hardware via OpenGL and DirectX. It is used by video playback software,
    14 emulators, and popular games including Valve's award winning catalog
    15 and many Humble Bundle games.
    17 The current version supports Windows, Mac OS X, Linux, iOS, and Android.
    18 The code contains support for other operating systems but those are not
    19 officially supported.
    21 SDL is written in C, but works with C++ natively, and has bindings to
    22 several other languages, including C#, Python and more in progress.
    24 This library is distributed under the zlib license, which can be found
    25 in the file "COPYING.txt".
    27 The best way to learn how to use SDL is to check out the header files in
    28 the "include" subdirectory and the programs in the "test" subdirectory.
    29 The header files and test programs are well commented and always up to date.
    30 More documentation and FAQs are available online at:
    33 If you need help with the library, or just want to discuss SDL related
    34 issues, you can join the developers mailing list:
    37 Enjoy!
    38 	Sam Lantinga				(