Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDL_RenderSetClipRect doesn't work properly when use SDL_RenderSetLogicalSize #1245

Closed
SDLBugzilla opened this issue Feb 10, 2021 · 0 comments

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: 2.0.1
Reported for operating system, platform: Windows 8, x86_64

Comments on the original bug report:

On 2013-11-24 16:35:06 +0000, neo wrote:

Created attachment 1473
An example from code.

-------------Info machine:---------
OS: Win8 (64bit)
SDL Version: 2.0.1
HW Video: AMD Radeon HD 7600M series

--------------Code example:-----------------------------

//Now i'm window 1280x800 [for example]
SDL_Window* win = SDL_CreateWindow("title",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,1280,800,SDL_WINDOW_RESIZABLE);

... //[create renderer with SDL_RENDERER_ACCELERATED]

//My application is designed for 800x600
SDL_RenderSetLogicalSize(renderer,800,600);

SDL_Texture* texture = ... //load all

//main loop
while(true){
SDL_RenderClear(renderer);
SDL_RenderSetClipRect(renderer, Rect(0,0,800,600)); //Rect = easy SDL_Rect wrapper class.
SDL_RenderCopy(renderer,texture,NULL,NULL);
SDL_RenderSetClipRect(renderer,NULL);
SDL_RenderPresent(renderer);
}


As you can see from the attached 'SDL_RenderSetClipRect' does not work well
because the area of the clip does not coincide with the area set on 'SDL_RenderSetLogicalSize'.

On 2014-01-06 15:19:57 +0000, wrote:

*** Bug 2336 has been marked as a duplicate of this bug. ***

On 2014-06-07 20:15:50 +0000, Leonardo wrote:

Created attachment 1674
Uses viewport x and y to set cliprect x/y

Hello. This bug happens because the viewport x/y is not being taken in consideration when setting the clipping rectangle (and render logical size is implemented as a combination of viewport and scale)

With the proposed patch, I've fixed this problem for the OpenGL[ES[2]] renderers but I have no idea if such problems occur in the DirectX renderer (couldn't be sure after superficially analyzing its code). Also I havent tested it in more odd combinations of scaling, viewport, target textures, etc.

As a workaround until this is fixed, one can get the viewport and add its x/y coordinates to the clipping rectangle:

SDL_Rect clip;
SDL_RenderGetViewport(renderer, &clip);
clip.x += 100, clip.y += 100, clip.w = 100, clip.w = 100;
SDL_RenderSetClipRect(renderer, &clip);

On 2014-09-26 02:21:40 +0000, wrote:

Created attachment 1882
add viewport x/y to clipping rectangle

Patch fixes the issue.

Workaround for unpatched SDL:

SDL_Rect c = {...};  // clipping rectangle
SDL_Rect vp;
SDL_RenderGetViewport(renderer, &vp);
c.x += vp.x;
c.y -= vp.y;
SDL_RenderSetClipRect(renderer, &c);

On 2015-01-30 13:07:38 +0000, Vii wrote:

Created attachment 2010
Adds viewport x/y to cliprect in UpdateClipRect + D3D

Hello. I was affected by this bug and found Leonardo's patch to work better than raincomplex's. I guess it's better to add the viewport coordinates when the driver updates the scissor rect than to do it beforehand.
Attached patch is the same as Leonardo's but with fix for D3D added.

On 2015-02-18 21:44:21 +0000, Ryan C. Gordon wrote:

*** Bug 2336 has been marked as a duplicate of this bug. ***

On 2015-05-29 02:01:54 +0000, Sam Lantinga wrote:

Fixed, thanks!
https://hg.libsdl.org/SDL/rev/1d13a878b066

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant