Qt 有加法混合模式吗?
Does Qt have an additive blend mode?
QPainter 有多种合成模式,但none 称为加法。我很感兴趣,因为加法混合一直在游戏中用于照明/粒子。
覆盖模式是唯一具有类似照明效果的模式。
编辑:我想通了,下面是如何在 Qt 中高效地制作不同颜色的灯。
在构造函数中或任何地方,而不是在绘制事件中:
light = QPixmap("light.png");
QPainter pix(light);
pix.setCompositionMode(QPainter::CompositionMode_Overlay);
pix.fillRect(light.rect(), QColor(255, 0, 0, 255)); // colorize the light in any color
绘画事件:
// Do drawing, e.g. a background
p.drawPixmap(0, 0, QPixmap("background.png"));
// draw the lighting
p.setCompositionMode(QPainter::CompositionMode_Plus);
p.drawPixmap(100, 100, light);
您可以根据需要重复使用相同的像素图,并使用不同的不透明度或大小等进行绘制。
QPainter::CompositionMode_Plus
的文档说:
Both the alpha and color of the source and destination pixels are added together.
QPainter 有多种合成模式,但none 称为加法。我很感兴趣,因为加法混合一直在游戏中用于照明/粒子。 覆盖模式是唯一具有类似照明效果的模式。
编辑:我想通了,下面是如何在 Qt 中高效地制作不同颜色的灯。
在构造函数中或任何地方,而不是在绘制事件中:
light = QPixmap("light.png");
QPainter pix(light);
pix.setCompositionMode(QPainter::CompositionMode_Overlay);
pix.fillRect(light.rect(), QColor(255, 0, 0, 255)); // colorize the light in any color
绘画事件:
// Do drawing, e.g. a background
p.drawPixmap(0, 0, QPixmap("background.png"));
// draw the lighting
p.setCompositionMode(QPainter::CompositionMode_Plus);
p.drawPixmap(100, 100, light);
您可以根据需要重复使用相同的像素图,并使用不同的不透明度或大小等进行绘制。
QPainter::CompositionMode_Plus
的文档说:
Both the alpha and color of the source and destination pixels are added together.