1 year ago
#253606

black_gay
Qt, particle system and additive blending
I’m creating a particle system using Qt and c++. I want to blend colours of the particles that overlap each other – adding the RGB values on top of each other, so colours would get brighter, something like this:
My code looks like this:
In custom QGraphicsScene class:
QPixmap* pixmap2 = new QPixmap("E:\\Qt_workspace\\1\\smoke5.png");
pixmap2->setDevicePixelRatio(0.5);
QPointF origin2 = {250, 100};
QPainter pix2(pixmap2);
pix2.setCompositionMode(QPainter::CompositionMode_Plus);
pix2.drawPixmap(origin2, *pixmap2);
pix2.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, true);
particleSystem2 = new ParticleSystem(this, pixmap2, origin2);
v_particleSystem.push_back(particleSystem2);
And i create particles in a loop:
void Level1::advance()
{
for (int i = 0; i < v_particleSystem.size(); ++i) {
v_particleSystem\[i\]->applyForce(gravity);
QVector2D v = { (float)player->x(), (float)player->y() };
repeller->update(v);
v_particleSystem[i]->applyReppeler(repeller);
v_particleSystem[i]->addParticle();
v_particleSystem[i]->run();
}
update(sceneRect); ///so items dont leave any artifacts though works without it when
using m_view->viewport()->repaint();
m_view->viewport()->repaint();
And Particle class derives from QGraphicsPixmapItem
Any idea how to achieve additive blending?
c++
qt
graphics
blending
particle-system
0 Answers
Your Answer