Drawing 2D geometric primitives
In this recipe, we will learn how to draw the following 2D geometric shapes, as filled and stroked shapes:
Circle
Ellipse
Line
Rectangle
Getting ready
Include the necessary header to draw in OpenGL using Cinder commands.
Add the following line of code at the top of your source file:
#include "cinder/gl/gl.h"
How to do it…
We will create several geometric primitives using Cinder's methods for drawing in 2D. Perform the following steps to do so:
Let's begin by declaring member variables to keep information about the shapes we will be drawing.
Create two
ci::Vec2f
objects to store the beginning and end of a line, aci::Rectf
object to draw a rectangle, aci::Vec2f
object to define the center of the circle, and afloat
object to define its radius. Finally, we will createaci::Vec2f
to define the ellipse's radius and twofloat
objects to define its width and height.Let's also declare two
ci::Color
objects to define the stroke and fill colors.Vec2f mLineBegin,mLineEnd; Rect...