Search code examples
c++alphacinder

Changing alpha in Cinder


I'm trying to have my particles fade away with time. I don't seem to be changing the opacity at all though. Any idea what the problem is?

class Particle
{

public:

    Particle();
    Particle( ci::Vec2f );
    void update();
    void draw();

    ci::Vec2f   mLoc;
    ci::Vec2f   mDir;
    float       mVel;
    float       trans;

    ci::ColorA       mColor;
    float           mRadius;

    float col_1,col_2,col_3;
};


void Particle::update()
{
  mLoc+=mDir*mVel/2;
  trans+=0.1;
  mColor=ColorA(col_1,col_2,col_3,trans); 
}

void Particle::draw()
{ 
 gl::color(mColor);
 gl::drawSolidCircle(mLoc,mRadius);
}

Solution

  • It looks like you need to enable alpha blending for example:

    gl::enableAlphaBlending();
    gl::color( mColor );
    
    gl::drawSolidCircle(mLoc,mRadius);
    
    gl::disableAlphaBlending();
    

    This discussion has more details: http://forum.libcinder.org/topic/beginner-question-changing-alpha-of-a-texture#23286000000675041