ofRect isn't quite rectangular
ofRect very commonly has a little chunk missing from one corner.
there is also a discrepancy between the filled and outline rectangles. it's not clear whether the outline rect should be within the bounds of the filled rect, or enclosing the filled rect, and in practice it can be a little of both.
here's a function that kind of solves it, but the problem is a bit deeper:
void ofRectSmart(int x, int y, int width, int height, bool inner = true) {
if(ofGetFill()) {
ofRect(x, y, width, height);
} else {
if(inner) {
ofRect(x + .5, y + .5, width - 1, height - 1);
} else {
ofRect(x - .5, y - .5, width + 1, height + 1);
}
}
}
void ofApp::draw() {
float x = mouseX / 4.;
float y = mouseY / 4.;
float width = mouseX / 2.;
float height = mouseY / 2.;
if(ofGetKeyPressed(' ')) {
ofTranslate(.5, .5);
}
ofBackground(128);
ofSetColor(0);
ofFill();
ofRectSmart(x, y, width, height);
ofSetColor(255);
ofNoFill();
if(ofGetMousePressed(0)) {
ofRectSmart(x, y, width, height, true);
} else if(ofGetMousePressed(2)) {
ofRectSmart(x, y, width, height, false);
}
}
the issue is that where exactly a line is drawn depends on subpixel values being passed to GL.
i tried to eradicate this by making ofRectSmart take only integer values. this means that everything ofRectSmart draws is correct (no chunks missing). but only if there are no other subpixel transformations.
if you try the code out, and press the spacebar to add a (.5, .5) offset, you'll see that you introduce a chunk or a mismatch between the fill and outline shapes.
regardless, i think having a rect that is (x + .5, y + .5, width - 1, height - 1) for the outline case would be really nice. if this is desired, i can go into the core and make that change.
Yeah, I notice that the edges of the lines don;t match up, especially when increasing the line width. Is there a setting on line ending mitering etc that comes with the inclusion of cairo?
Was this ever resolved? I'm experiencing it on 0.8.1 - I ended up drawing each side of the rectangle as a separate ofRect.
this was never resolved. it gets even messier when you start using hidpi screens. watching this bug for years, my intuition is that the current implementation is as correct as it will ever be. on some screens, and some graphics cards, and some OSes it looks better, on others it looks worse, but i'm going to close this because i don't think there is a better solution without significant changes to how we draw things.