Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: BlendMode  (Read 8139 times)

0 Members and 2 Guests are viewing this topic.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: BlendMode
« Reply #15 on: December 24, 2014, 05:37:38 pm »
Hmm... It's really hard to spot the difference, especially since there's no sprite behind the grid.
Laurent Gomila - SFML developer

cheeseboy

  • Newbie
  • *
  • Posts: 36
    • View Profile
Re: BlendMode
« Reply #16 on: December 24, 2014, 06:05:16 pm »
I broke the sprite part atm but look closely at the grid intersections on the right one..

Edit: After fixing sprite loader I've noticed that lines are incorrect color. The opposite of flamingo pink is lime green not black

« Last Edit: December 24, 2014, 07:12:52 pm by cheeseboy »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: BlendMode
« Reply #17 on: December 25, 2014, 01:31:53 am »
sf::BlendMode(sf::BlendMode::SrcAlpha, sf::BlendMode::One, sf::BlendMode::Subtract)
?
Laurent Gomila - SFML developer

cheeseboy

  • Newbie
  • *
  • Posts: 36
    • View Profile
Re: BlendMode
« Reply #18 on: December 25, 2014, 07:21:57 am »
Also gives me black lines.

cheeseboy

  • Newbie
  • *
  • Posts: 36
    • View Profile
Re: BlendMode
« Reply #19 on: December 27, 2014, 07:19:19 pm »
Here's a demo. When you set an alpha lines turn black. Otherwise the color is correct...

#include <SFML/Graphics.hpp>

static const unsigned char colorbars_png[] = {137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,0,48,0,0,0,36,8,2,0,0,0,64,39,46,93,0,0,0,9,112,72,89,115,0,0,11,19,0,0,11,19,1,0,154,156,24,0,0,0,7,116,73,77,69,7,222,12,27,19,55,13,86,222,43,192,0,0,4,59,73,68,65,84,88,195,205,88,205,139,28,69,20,255,189,170,234,158,222,158,217,79,87,252,88,69,86,141,39,97,131,26,241,100,188,132,69,193,147,120,204,65,114,240,47,136,135,176,68,19,61,120,217,131,1,5,209,187,10,226,69,194,70,65,16,196,21,67,68,163,136,9,49,168,224,199,94,178,201,154,238,158,174,207,231,161,39,189,51,227,70,214,204,236,206,62,24,168,46,170,186,223,251,189,223,251,213,171,33,102,70,159,241,167,8,139,0,117,79,157,160,19,39,113,60,244,206,34,188,196,254,20,145,173,94,66,68,145,141,142,126,120,244,181,183,95,69,163,123,183,65,246,50,178,215,65,245,110,6,240,100,227,236,215,226,64,212,251,113,129,225,27,15,178,106,39,28,162,109,175,218,98,165,26,142,11,55,114,65,68,52,216,171,134,131,80,77,68,102,230,109,166,108,71,29,34,162,154,215,3,178,77,12,236,74,111,214,120,208,216,196,96,236,165,42,87,204,92,33,180,133,136,236,166,67,188,237,218,217,53,132,110,90,110,163,66,136,177,167,56,84,131,84,87,217,224,54,168,67,255,246,99,196,194,88,101,138,153,59,3,12,10,212,224,194,72,55,131,106,148,74,93,67,69,32,236,133,163,99,19,33,26,80,55,134,71,234,154,76,163,20,198,110,185,222,43,28,234,147,102,194,232,251,33,234,73,25,254,87,63,196,59,200,161,174,148,209,40,73,125,235,77,254,238,232,208,224,135,199,78,32,52,244,22,150,182,222,202,255,33,208,68,60,164,186,87,89,209,63,37,89,142,49,128,86,151,59,215,27,49,198,163,44,128,168,118,140,198,96,45,116,77,106,16,33,178,32,134,75,81,198,189,209,148,128,223,12,159,0,1,52,18,26,87,253,23,49,117,232,72,207,115,0,158,16,143,191,145,126,3,150,155,179,229,216,11,207,191,247,244,179,7,65,85,81,19,0,144,192,251,191,227,180,133,227,186,119,117,18,103,14,242,254,119,17,217,46,188,13,209,155,132,183,80,223,175,153,193,1,39,63,192,131,11,240,174,39,127,234,210,47,117,200,204,140,0,158,83,45,52,31,241,92,117,132,0,131,115,220,126,133,238,208,223,51,5,112,167,23,227,6,227,15,193,23,4,12,24,157,140,105,133,143,31,179,63,222,235,83,211,238,184,25,11,114,101,152,213,14,112,170,58,88,36,88,130,105,102,94,60,244,0,156,5,5,40,64,18,0,168,99,47,178,15,33,120,239,189,243,222,91,231,239,9,238,42,185,204,89,107,173,117,206,26,99,11,178,24,55,231,158,49,214,88,99,141,49,198,88,19,180,249,203,154,73,99,75,163,181,49,198,88,107,218,218,175,126,182,122,103,241,202,177,9,91,2,184,141,241,176,192,188,207,158,90,253,89,226,171,24,191,34,2,246,49,47,128,238,127,167,121,215,233,243,192,15,72,215,177,31,120,84,225,110,9,98,246,128,13,222,90,99,180,49,70,235,188,44,175,182,203,178,221,177,162,93,20,69,94,108,184,124,195,230,121,94,20,69,150,101,89,150,229,121,158,155,60,43,179,44,203,242,34,207,179,188,250,217,191,55,14,0,103,231,1,0,251,128,231,128,69,20,247,225,12,196,41,132,47,208,12,88,36,28,6,14,241,90,19,159,0,31,97,226,50,14,19,142,52,176,16,65,85,244,242,65,184,64,206,195,122,14,62,196,222,123,239,156,119,206,187,200,69,145,139,35,114,81,100,162,200,40,165,149,210,157,129,214,202,106,101,181,50,90,89,45,141,150,70,59,34,36,2,105,0,1,41,144,0,13,120,32,108,150,41,3,1,112,20,3,99,80,41,210,20,41,33,105,64,68,80,43,43,43,33,4,41,101,8,161,226,145,115,14,128,181,54,132,96,173,245,222,91,107,157,115,82,202,36,73,148,82,73,146,76,79,79,107,173,173,173,210,103,156,115,101,89,122,239,219,237,246,133,139,23,175,92,250,233,203,235,148,17,176,6,124,7,34,92,155,197,183,192,122,0,216,131,214,64,231,32,29,214,39,113,30,225,79,232,107,184,76,248,60,194,111,18,36,132,32,162,185,185,57,41,229,204,204,76,171,213,106,52,26,179,179,179,82,202,201,201,201,56,142,91,173,86,146,36,173,86,43,77,211,234,81,41,53,53,53,37,132,104,54,155,73,146,196,113,60,49,49,193,204,211,211,211,206,185,229,229,229,165,165,37,185,121,199,238,65,166,71,235,136,234,38,188,214,67,85,1,227,189,7,16,66,232,240,219,123,34,10,33,116,95,144,169,215,196,13,147,82,86,81,41,165,0,8,33,0,248,90,38,121,91,26,29,186,255,31,170,63,208,55,168,172,251,156,234,83,227,234,74,95,249,93,13,234,24,110,217,254,1,178,148,101,54,121,28,135,134,0,0,0,0,73,69,78,68,174,66,96,130};

class Grid : public sf::Drawable, public sf::Transformable
{

public:

    Grid(unsigned int Xsep, unsigned int Ysep, unsigned int CanvasW, unsigned int CanvasH)
    {

        m_vertices.setPrimitiveType(sf::Lines);
        m_vertices.clear();

        for (int i=((CanvasW/2)-Xsep); i > 0; i-=Xsep)
        {
            m_vertices.append(sf::Vector2f(i,0));
            m_vertices.append(sf::Vector2f(i,CanvasH));
            m_vertices.append(sf::Vector2f(CanvasW-i,0));
            m_vertices.append(sf::Vector2f(CanvasW-i,CanvasH));
        }

        for (int i=((CanvasH/2)-Ysep); i > 0; i-=Ysep)
        {
            m_vertices.append(sf::Vector2f(0,i));
            m_vertices.append(sf::Vector2f(CanvasW,i));
            m_vertices.append(sf::Vector2f(0,CanvasH-i));
            m_vertices.append(sf::Vector2f(CanvasW,CanvasH-i));
        }

        m_vertices.append(sf::Vector2f(0,CanvasH / 2));
        m_vertices.append(sf::Vector2f(CanvasW,CanvasH / 2));
        m_vertices.append(sf::Vector2f(CanvasW / 2, 0));
        m_vertices.append(sf::Vector2f(CanvasW / 2,CanvasH));
    }

    void setFillColor(const sf::Color &color)
    {
        unsigned vertex_count = m_vertices.getVertexCount();

        for(unsigned int i=0; i < vertex_count; i++)
            m_vertices[i].color = color;
    }


private:

    sf::VertexArray m_vertices;
    void draw(sf::RenderTarget& target, sf::RenderStates states) const
    {
        states.transform *= getTransform();
        states.blendMode = sf::BlendMode(sf::BlendMode::SrcAlpha, sf::BlendMode::One, sf::BlendMode::Subtract); //BlendMode here
        target.draw(m_vertices, states);
    }

};

int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "Grid Test");

    Grid grid = Grid(16,16,800,600);
    grid.setFillColor(sf::Color(255,255,255,40)); //without alpha lines are inverse

    sf::Texture texture;
    texture.loadFromMemory(colorbars_png, sizeof(colorbars_png), sf::IntRect(0,0,48,48));


    sf::Sprite sprite;
    sprite.setTexture(texture);
    sprite.setTextureRect(sf::IntRect(0, 0, 800, 600));
    sprite.setScale(16.6, 18.75);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear(sf::Color::Black);
        window.draw(sprite);
        window.draw(grid);
        window.display();
    }

    return 0;
}

 
« Last Edit: December 27, 2014, 08:57:27 pm by cheeseboy »

 

anything