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

[rshapes] Fix pixel offset issue with DrawRectangleLines #4669

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Bigfoot71
Copy link
Contributor

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:

BeginDrawing();  // rlLoadIdentity();

rlPushMatrix();
rlScalef(2, 5, 1);

Matrix mv = rlGetMatrixModelview();    //< m0 = 1 | m5 = 1
Matrix t = rlGetMatrixTransform();     //< m0 = 2 | m5 = 5

rlPopMatrix();

So, I simply replaced the call to rlGetMatrixModelview() with rlGetMatrixTransform(), fixed how the offsets are applied, and added consideration for m5 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);:
image

The red is at a transparency of 127, so we can see the black underneath.

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.

1 participant