What' the difference between ofRectangle & ofDrawRectangle?

what’ the difference between ofRectangle & ofDrawRectangle?

Hi, a lot.
ofRectangle is a class that hold a position and a width and height, hence it defines a rectangle.
Besides this it has a lot of useful functions for aligning and scaling rectangles and checking if a point is inside of it. These are super useful for making gui’s, buttons, placing images, etc.
ofDrawRectangle is a function that simply draws a rectangle on screen. It can receive as a parameter an ofRectangle as well as x, y, width and height.
There’s an example that shows how to use the align and scale methods of ofRectangle.



thank u so much!! great explanation!

An example of placing videos, which also works with images as @roymacdonald said:

// .h
ofRectangle topLeft, topRight, bottomLeft, bottomRight;

// setup
topLeft.set(0, 0, ofGetWidth()/2, ofGetHeight()/2);
topRight.set(ofGetWidth()/2, 0, ofGetWidth()/2, ofGetHeight()/2);
bottomLeft.set(0, ofGetHeight()/2, ofGetWidth()/2, ofGetHeight()/2);
bottomRight.set(ofGetWidth()/2, ofGetHeight()/2, ofGetWidth()/2, ofGetHeight()/2);

// draw

Without ofRectangle the code is shorter, but your intention is less clear:

video1.draw(0, 0, ofGetWidth()/2, ofGetHeight()/2);
video2.draw(ofGetWidth()/2, 0, ofGetWidth()/2, ofGetHeight()/2);
video3.draw(0, ofGetHeight()/2, ofGetWidth()/2, ofGetHeight()/2);
video4.draw(ofGetWidth()/2, ofGetHeight()/2, ofGetWidth()/2, ofGetHeight()/2);
1 Like