Issue with canvas
« on: 31 May 2015, 23:29:26 »
I have a following issue. I have a panel with canvas inside of it...into the canvas Im drawing a sprite as a background, mainly because I need to have some sections with alpha channel. The problem is that the channel is somehow not working. Sections with alpha channel are remaining black....btw Im drawing everything into the single rendertarget.

*

texus

  • *****
  • 1161
    • View Profile
    • Texus's Blog
Re: Issue with canvas
« Reply #1 on: 31 May 2015, 23:30:51 »
Could you post some minimal code that does what you describe so that I can easily test it here?

Re: Issue with canvas
« Reply #2 on: 31 May 2015, 23:54:07 »
int main()
{
        sf::RenderWindow window(sf::VideoMode(800, 600), "Test");
        tgui::Gui gui(window);

        tgui::Panel::Ptr panel(gui);
        panel->setSize(100,100);
        panel->setPosition(100, 100);

        tgui::Canvas::Ptr canvas(*panel);
        canvas->setPosition(0, 0);
        canvas->setSize(panel->getSize().x, panel->getSize().y);

        sf::Texture tex;
        // load some texture with alpha channel
        sf::Sprite sprite;
        sprite.setTexture(tex);

        while(window.isOpen())
        {
                window.clear(sf::Color::Blue);
                gui.draw();

                canvas->clear();
                canvas->draw(sprite);
                canvas->display();

                window.display();
        }
}
 

I want to achieve that the sections with alpha mask in sprite will work on scene drawn before before panel (in this case just blue color)

*

texus

  • *****
  • 1161
    • View Profile
    • Texus's Blog
Re: Issue with canvas
« Reply #3 on: 01 June 2015, 00:04:56 »
Quote
canvas->clear();
That code will clear the canvas with a black color.
Change it to
canvas->clear(sf::Color::Transparent);

The Panel also has a background color. So you should add this line as well:
panel->setBackgroundColor(sf::Color::Transparent);

Re: Issue with canvas
« Reply #4 on: 01 June 2015, 00:18:02 »
I tried to clear canvas with transparent color before...but finally setting also panel background color helped! Thank you!