Animating effects

Let's make a simple effect animation by using the tricks we just learned and the update() method. We have to modify the code in the setup() method implementation so it looks similar to the following:

surface = Surface( loadImage( loadAsset("OurImage.png") ) );
  
// int threshold = 200; // comment or remove this line
Area area = surface.getBounds();
Surface::Iter iter = surface.getIter( area );
while( iter.line() ) {
  while( iter.pixel() ) {
    iter.r() += 1;
    iter.g() += 2;
    iter.b() += 3;
  }
}

texture = gl::Texture( surface );

Next we have to cut and paste all the code except the surface initialization to the update() method implementation as follows:

void BasicEffectsApp::setup() {
  surface = Surface( loadImage( loadAsset("OurImage.png") ) );
}

void BasicEffectsApp::update() {
  Area area = surface.getBounds();
  Surface::Iter iter = surface.getIter( area );
  while( iter.line() ) {
    while( iter.pixel() ) {
      iter.r() += 1;
      iter.g() += 2;
      iter.b() += 3;
    }
  }
  
  texture = gl::Texture( surface );
}

With that done, compile and run the project, and see what happens:

Animating effects

In the preceding screenshot you can see an animation that looks like some kind of acid eating and that transforms all the surfaces of the image.

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

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