[rshapes] Fix pixel offset issue with DrawRectangleLines
#4669
+14
−11
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As requested here (#4666 (comment)), here is the fix for
DrawRectangleLines
.And good news! This fix also handles scale transformations!
There was initially a small error in applying the offsets, which has been corrected.
But most importantly, strangely, the function
rlGetMatrixModelview()
seems to only return the first matrix of the transformation stack, which could be considered just the view matrix if we want to put it that way...However, by calling
rlGetMatrixTransform()
, we seem to get the actual 'modelView' matrix, which corresponds to all the accumulated transformation matrices on the stack.Here’s a little example:
So, I simply replaced the call to
rlGetMatrixModelview()
withrlGetMatrixTransform()
, fixed how the offsets are applied, and added consideration form5
in non-uniform scales along both axes.Maybe
rlGetMatrixModelview()
is misleading in its name? It's up to you to tell me.Also, maybe this adjustment could be applied to all other line drawing functions? I’m not sure how relevant that could be, so feel free to share your thoughts on that too.
If that’s the case, for
DrawRectangleRoundedLinesEx()
, it would still require some testing to be sure of what we are doing.Here is an example with a 10x10 square scaled using
rlScalef(5, 2, 1);
:The red is at a transparency of
127
, so we can see the black underneath.