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

Fix SDL gradient overlaps + SDL rendering of sector-wide gradients #2597

Merged
merged 4 commits into from
Aug 24, 2023

Conversation

Narre
Copy link
Contributor

@Narre Narre commented Aug 22, 2023

This was discovered by FrostC.
Due to the conversion from floating point to integer values, there was a "build-up" of rounding errors when splitting gradients to single-colour rectangles for rendering, which caused that some of the rectangles would overlap by one pixel. This PR adds a check that ensures that the next step always starts at previous step + previous height/width (both of those are already integers), plus it always shortens the height/width by one when the rounding error exceeds one (checks the actual position of the rectangle calculated by adding the width/height of the previous one to its starting position against the position calculated directly using the floats), so the gradient isn't stretched. This is the point at which the overlap would previously occur.
This bug was introduced in #2549 . I didn't notice it because the overlap can only be seen when the overlapping rectangles change the rendering outcome, i.e. when using the Additive blend mode.

before:
image
now:
image

EDIT:
While testing this PR, I found another bug. This one would cause sector-wide gradients (VERTICAL_SECTOR and HORIZONTAL_SECTOR) to render incorrectly, so I also fixed that (see the video in the fourth comment).

@tobbi
Copy link
Member

tobbi commented Aug 22, 2023

Is this something that can occur for the horizontal version as well?

@Narre
Copy link
Contributor Author

Narre commented Aug 22, 2023

image
yes

@tobbi
Copy link
Member

tobbi commented Aug 22, 2023

Sorry, I misread the code. It's all good!

@Narre
Copy link
Contributor Author

Narre commented Aug 22, 2023

Alright, I also fixed this (which has been in the game before, it's not #2549 's fault):

022-2023-08-22_14.19.22.mp4

@Narre Narre changed the title Fix SDL gradient overlaps Fix SDL gradient overlaps + SDL rendering of sector-wide gradients Aug 22, 2023
@tobbi tobbi self-requested a review August 23, 2023 23:19
@tobbi tobbi merged commit 566b461 into SuperTux:master Aug 24, 2023
33 checks passed
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

Successfully merging this pull request may close these issues.

2 participants