SFML community forums

Help => Graphics => Topic started by: Jereli on April 09, 2016, 09:27:19 pm

Title: Blending colors
Post by: Jereli on April 09, 2016, 09:27:19 pm
Hi. I have are simple task. Mix the three colors (Cyan, Magenta, Yellow) to obtain black color. How i can get this?
My try dosent working right.
int main() {
        sf::RenderWindow window (sf::VideoMode(winW, winH), "CMYK CMYK CMYK");

        sf::Color cl_c(0, 255, 255, 85); //Cyan
        sf::Color cl_m(255, 0, 255, 85); //Magenta
        sf::Color cl_y(255, 255, 0, 85); //Yellow
       
        sf::CircleShape c1(50);
        c1.setPosition(70, 30);
        c1.setFillColor(cl_c);

        sf::CircleShape c2(50);
        c2.setPosition(150, 20);
        c2.setFillColor(cl_m);

        sf::CircleShape c3(50);
        c3.setPosition(100, 60);
        c3.setFillColor(cl_y);

       
        sf::Event event;
        while (window.isOpen()) {
                while (window.pollEvent(event)) {
                        if (event.type == sf::Event::Closed) {
                                window.close();
                                return 0;
                        }
                       
                        window.clear(sf::Color::White);
                        window.draw(c1);
                        window.draw(c2);
                        window.draw(c3);

                        window.display();
                }
        }
        return 0;
}
Title: Re: Blending colors
Post by: Mr_Blame on April 09, 2016, 11:01:17 pm
This blending will work only in CMYK while SFML is working in RGB.
Title: Re: Blending colors
Post by: fallahn on April 09, 2016, 11:26:50 pm
Unfortunately you can't just draw on top of things and expect them to blend. You should probably look at blend modes (http://www.sfml-dev.org/documentation/2.3.2/structsf_1_1BlendMode.php). In this case I believe you want sf::BlendMultiply (255 * 255 * 0 = 0 == Black).