Skip to content

Instantly share code, notes, and snippets.

@paulhoux
Created October 12, 2016 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulhoux/92a1a6abc8cea126392a3572dc12456b to your computer and use it in GitHub Desktop.
Save paulhoux/92a1a6abc8cea126392a3572dc12456b to your computer and use it in GitHub Desktop.
#include "cinder/app/App.h"
#include "cinder/app/RendererGl.h"
#include "cinder/gl/gl.h"
using namespace ci;
using namespace ci::app;
using namespace std;
class fadeoutApp : public App {
public:
void draw() override;
void resize() override;
void mouseMove( MouseEvent event ) override;
void render();
private:
gl::FboRef mFbo;
ci::ivec2 mMousePos;
};
void fadeoutApp::draw()
{
// Render scene to Fbo. This allows us to keep the contents of the previous
// frame.
render();
// Now render the scene to the main buffer.
gl::draw( mFbo->getColorTexture() );
}
void fadeoutApp::mouseMove( MouseEvent event )
{
// Keep track of the mouse position in window coordinates.
mMousePos = event.getPos();
}
void fadeoutApp::resize()
{
// Create an Fbo the size of the window.
mFbo = gl::Fbo::create( getWindowWidth(), getWindowHeight() );
// Clear once at setup.
gl::ScopedFramebuffer scpFbo( mFbo );
gl::ScopedViewport scpViewport( mFbo->getSize() );
gl::clear();
}
void fadeoutApp::render()
{
// Bind the Fbo and update the viewport.
gl::ScopedFramebuffer scpFbo( mFbo );
gl::ScopedViewport scpViewport( mFbo->getSize() );
// Enable pre-multiplied alpha blending.
gl::ScopedBlendPremult scpBlend;
// Draw transparent black rectangle.
gl::ScopedColor scpColor( 0, 0, 0, 4.0f / 255.0f );
gl::drawSolidRect( { 0, 0, (float)getWindowWidth(), (float)getWindowHeight() } );
// Draw a white circle.
gl::color( 1, 1, 1 );
gl::drawSolidCircle( mMousePos, 20 );
}
CINDER_APP( fadeoutApp, RendererGl )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment