Now that we know how to draw lines and circles, let's move to another geometric primitive that we can use—the rectangle.
As in the case of a circle, there is one function for drawing a filled rectangle and one function for drawing just the outline. They are drawSolidRect()
and drawStrokedRect()
respectively.
gl::color( 0, 0, 1 ); // set color to blue gl::drawSolidRect( Rectf( getWindowWidth()/2-20.0f, getWindowHeight()/2-20.0f, getWindowWidth()/2+20.0f, getWindowHeight()/2+20.0f ) ); gl::drawStrokedRect( Rectf( getWindowWidth()/2-120.0f, getWindowHeight()/2-120.0f, getWindowWidth()/2+120.0f, getWindowHeight()/2+120.0f ) );
Here we draw two rectangles, one filled (or solid) and one as an outline. Note that we pass just one parameter of the type Rectf
to both the functions. The simplest version of Rectf
is being constructed by using the coordinates of top-left and bottom-right corners of the rectangle. Most of the drawing APIs use x and y coordinates of the top-left corner and the width and height of the rectangle, so it could be a bit difficult to get used to this.
18.188.178.181