void HelloSvgApp::draw() { gl::clear(Color{0, 0, 0}); gl::clear(GL_STENCIL_BUFFER_BIT); mNanoVG->beginFrame(getWindowSize(), getWindowContentScale()); mNanoVG->translate(getWindowCenter()); mNanoVG->scale(vec2(0.75f * float(getWindowHeight()) / float(mDoc->getHeight()))); mNanoVG->translate(-mDoc->getBounds().getCenter()); mNanoVG->fontFace("Roboto"); mNanoVG->draw(*mDoc); mNanoVG->endFrame(); }
gl::Texture renderCairoToTexture( svg::DocRef doc ) { cairo::SurfaceImage srf; if( doc->getWidth() && doc->getHeight() ) srf = cairo::SurfaceImage( doc->getWidth(), doc->getHeight(), true ); else srf = cairo::SurfaceImage( 640, 480, true ); cairo::Context ctx( srf ); ctx.render( *doc ); srf.flush(); return gl::Texture( srf.getSurface() ); }
Surface renderCairo( svg::DocRef doc, const svg::RenderVisitor &visitor ) { cairo::SurfaceImage srf; if( doc->getWidth() && doc->getHeight() ) srf = cairo::SurfaceImage( doc->getWidth(), doc->getHeight(), true ); else srf = cairo::SurfaceImage( 640, 480, true ); cairo::Context ctx( srf ); ctx.setSourceRgb( 1, 1, 1 ); ctx.paint(); ctx.render( *doc, visitor ); srf.flush(); Surface result = srf.getSurface(); return srf.getSurface(); }
void GoodNightMorningApp::resize( ResizeEvent event ) { Rectf svgBounds = mCityscapeSvg->getBounds(); // get the native bounds of the SVG // fit the SVG proportionally into the window mDrawBounds = svgBounds.getCenteredFit( getWindowBounds(), true ); // Our SVG has two root groups, "Foreground" and "Background". Tweets are rendered between these two layers // Render each group into its own texture mForegroundTex = renderSvgGroupToTexture( *mCityscapeSvg, "Foreground", mDrawBounds, true ); mBackgroundTex = renderSvgGroupToTexture( *mCityscapeSvg, "Background", mDrawBounds, false ); }
void AnimatedRevealApp::update() { if( ( ! mDoc ) || mDone ) return; // we'll stop drawing filled after we've drawn new pixels that are 1% of the size of the image size_t imageSize, minArea; if( mDoc->getWidth() && mDoc->getHeight() ) imageSize = mDoc->getWidth() * mDoc->getHeight(); else imageSize = 640 * 480; minArea = 1 + imageSize * 0.01f; Surface frame = renderCairo( mDoc, SlowFillVisitor( mMinRenderElement, minArea, &mMinRenderElement, &mDone ) ); #if defined( RECORD_MOVIE ) mMovie.addFrame( frame ); if( mDone ) { mMovie.addFrame( frame ); // otherwise we seem to lose the last frame mMovie.finish(); } #endif mTex = gl::Texture::create( frame ); }
Shape2d getCenteredShape2dfromSVGDoc(svg::DocRef doc) { Shape2d s = doc->getShape(); s.transform( MatrixAffine2f::makeTranslate( -doc->getSize()/2 ) ); return s; }
void AnimatedRevealApp::load( const fs::path &path ) { mMinRenderElement = 0; try { if( path.extension() == ".svgz" ) // compressed mDoc = svg::Doc::createFromSvgz( loadFile( path ) ); else mDoc = svg::Doc::create( loadFile( path ) ); mDone = false; #if defined( RECORD_MOVIE ) mMovie = qtime::MovieWriter( fs::path( getHomeDirectory() + "AnimatedReveal.mov" ), mDoc->getWidth(), mDoc->getHeight() ); #endif } catch( ci::Exception &exc ) { console() << "failed to load doc, what: " << exc.what() << endl; } }