Skip to content

Instantly share code, notes, and snippets.

@jkosoy
Created October 15, 2012 21:42
Show Gist options
  • Save jkosoy/3895744 to your computer and use it in GitHub Desktop.
Save jkosoy/3895744 to your computer and use it in GitHub Desktop.
Cinder Drawing Tips
// originally from http://redpaperheart.com/blog/2012/08/handy-snippets-for-drawing-image-textures-in-cinder/
// thanks Daniel!
// ---------------------
/* draw a texture */
gl::draw(texture);
// ---------------------
/* Draw a texture into a specified rectangle, distort texture to fill rectangle: */
gl::draw(texture, Rectf(0,0,200,200));
// ---------------------
/* Draw a texture to fit completely into specified rectangle (no distortion/keeps aspect ratio, shows white space): */
Rectf destRect = Rectf(0,0,200,200);
gl::draw(texture, Rectf(texture.getBounds()).getCenteredFit(destRect, true));
// ---------------------
/* Draw a texture to fill a specified rectangle while retaining image proportions and not showing white space (texture is centered within the rectangle and overflow is masked/cropped): */
Rectf destRect = Rectf(0,0,200,200);
gl::draw(texture, Area(destRect.getCenteredFit(texture.getBounds(), true)), destRect);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment