Render clipping rectangle issue

Hi again.

I’ve got a second request :slight_smile:

SDL_RenderSetClipRect() is currently always relative to the point 0,0 of the window, but I’m not sure that this is the expected behavior.
If my game have a 4/3 resolution, and if I switch to fullscreen mode and have a 16/9 screen, the clipping rectangle haven’t same coordinates than with the windowed display.
The same thing happens if I use a render texture : the clipping rectangle is relative to the point 0,0 of the window, not the point 0,0 of the render target (in this case, I’m pretty sure that this is not the expected behaviour, unless I miss something)

I think the clipping rectangle should just be relative to the viewport (or to the point 0,0 of the render texture, if any).

Am I missing something or is it really an issue ?


I have the same issue. In fullscreen desktop, using render clipping rectangle causes misaligned pixels.

I have a desktop resolution of 1366x768. My game draws on a renderer of 320x240. Therefore, in fullscreen desktop, the rendering is scaled to 1024x768, with a factor of 3.2. There are two black columns of 171 pixels each on the left and the right of the screen. Everything is okay so far.

The problem is that I cannot use SDL_RenderSetClipRect(). SDL_RenderSetClipRect() uses unscaled coordinates while being relative to the window. So okay, to end up at the position of my renderer, I have to add (171 / 3.2) pixels. With unscaled coordinates, this is not an integer number: 53.4375. SDL_RenderGetViewport() gives integer numbers: 53. I don’t how to make it right.

The result is that when I use SDL_RenderSetClipRect(), in fullscreen desktop mode, whatever I draw on the renderer is slightly shifted to the left, of less than one pixel.