-
-
Save paulhoux/92a1a6abc8cea126392a3572dc12456b to your computer and use it in GitHub Desktop.
In response to a post on libcinder.org (http://discourse.libcinder.org/t/super-simple-fade-effect-not-working/317)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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