Skip to content

Commit 337d726

Browse files
committed
fix pixel offset issue with DrawRectangleLines
1 parent ddd86a3 commit 337d726

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/rshapes.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -807,22 +807,25 @@ void DrawRectangleGradientEx(Rectangle rec, Color topLeft, Color bottomLeft, Col
807807
// but it solves another issue: https://github.com/raysan5/raylib/issues/3884
808808
void DrawRectangleLines(int posX, int posY, int width, int height, Color color)
809809
{
810-
Matrix mat = rlGetMatrixModelview();
811-
float zoomFactor = 0.5f/mat.m0;
810+
Matrix mat = rlGetMatrixTransform();
811+
float xOffset = 0.5f/mat.m0;
812+
float yOffset = 0.5f/mat.m5;
813+
812814
rlBegin(RL_LINES);
813815
rlColor4ub(color.r, color.g, color.b, color.a);
814-
rlVertex2f((float)posX - zoomFactor, (float)posY);
815-
rlVertex2f((float)posX + (float)width + zoomFactor, (float)posY);
816+
rlVertex2f((float)posX + xOffset, (float)posY + yOffset);
817+
rlVertex2f((float)posX + (float)width - xOffset, (float)posY + yOffset);
816818

817-
rlVertex2f((float)posX + (float)width, (float)posY - zoomFactor);
818-
rlVertex2f((float)posX + (float)width, (float)posY + (float)height + zoomFactor);
819+
rlVertex2f((float)posX + (float)width - xOffset, (float)posY + yOffset);
820+
rlVertex2f((float)posX + (float)width - xOffset, (float)posY + (float)height - yOffset);
819821

820-
rlVertex2f((float)posX + (float)width + zoomFactor, (float)posY + (float)height);
821-
rlVertex2f((float)posX - zoomFactor, (float)posY + (float)height);
822+
rlVertex2f((float)posX + (float)width - xOffset, (float)posY + (float)height - yOffset);
823+
rlVertex2f((float)posX + xOffset, (float)posY + (float)height - yOffset);
822824

823-
rlVertex2f((float)posX, (float)posY + (float)height + zoomFactor);
824-
rlVertex2f((float)posX, (float)posY - zoomFactor);
825+
rlVertex2f((float)posX + xOffset, (float)posY + (float)height - yOffset);
826+
rlVertex2f((float)posX + xOffset, (float)posY + yOffset);
825827
rlEnd();
828+
826829
/*
827830
// Previous implementation, it has issues... but it does not require view matrix...
828831
#if defined(SUPPORT_QUADS_DRAW_MODE)
@@ -845,7 +848,7 @@ void DrawRectangleLines(int posX, int posY, int width, int height, Color color)
845848
rlVertex2f((float)posX + 1, (float)posY + (float)height);
846849
rlVertex2f((float)posX + 1, (float)posY + 1);
847850
rlEnd();
848-
//#endif
851+
#endif
849852
*/
850853
}
851854

0 commit comments

Comments
 (0)