Issue with canvas

Started by Pete, 31 May 2015, 23:29:26

Pete

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

Could you post some minimal code that does what you describe so that I can easily test it here?

Pete

Code (cpp) Select

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

Quote
Code (cpp) Select
canvas->clear();
That code will clear the canvas with a black color.
Change it to
Code (cpp) Select
canvas->clear(sf::Color::Transparent);

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

Pete

I tried to clear canvas with transparent color before...but finally setting also panel background color helped! Thank you!