Other useful drawing functions

These are the very basic drawing functions, and actually you can do a lot with them if you use them in a creative way. But here are a couple of other functions that are worth checking out. They are given in the following code snippet:

gl::color( 1, 1, 0 );
gl::drawSolidEllipse( Vec2f(150,100), 100, 50, 10);
gl::drawStrokedEllipse( Vec2f(400,300), 100, 175, 15);
gl::drawSolidRoundedRect(
Rectf(550,150,600,300), 20, 4 );
gl::drawStrokedRoundedRect(
Rectf(20,300,200,400), 10, 10 );

Experiment with the properties of these functions to fully understand what they mean. Compile and run the project and you should see an image similar to the following screenshot:

Other useful drawing functions

Try to re-size the window by dragging the bottom right corner. You will see the difference between graphics that are drawn relative to the window's size and the ones that are not. Keep this in mind when creating your own application.

The following is the full code for drawing all the shapes, in case you did not understand which line of code goes where:

void BasicShapesApp::draw(){
  // clear out the window with black
  gl::clear( Color( 0, 0, 0 ) );
  
  // draw some lines
  glLineWidth( 2 ); // set line width to 2
  gl::color( 0, 1, 1 ); // set color to cyan
  gl::drawLine( Vec2f(0,0),
        Vec2f(getWindowWidth(),getWindowHeight()) );
  gl::color( 1, 0, 0 ); // set color to red
  gl::drawLine( Vec2f(0,getWindowHeight()),
        Vec2f(getWindowWidth(),0) );
    
  // draw some circles
    gl::color( 1, 0, 1 ); // set color to magenta
    gl::drawSolidCircle( getWindowCenter(), 50, 5 );
    glLineWidth( 4 );
    gl::drawStrokedCircle( getWindowCenter(), 100, 5 );
    
  // draw rectangles
    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 ) );
    
  // draw rest
    gl::color( 1, 1, 0 );
    gl::drawSolidEllipse( Vec2f(150,100), 100, 50, 10);
    gl::drawStrokedEllipse( Vec2f(400,300), 100, 175, 15);
    gl::drawSolidRoundedRect(
         Rectf(550,150,600,300), 20, 4 );
    gl::drawStrokedRoundedRect(
         Rectf(20,300,200,400), 10, 10 );
}

That's it! This is one of the simplest way to draw basic shapes with Cinder.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.163.250