I have been enjoying SFML2 since switching over recently, but I cannot get transparency to work at all. Searching the forums and google has not turned up anything yet on why my attempts are not working. I have been trying to get this working for hours so if you can give me any suggestions on what to try next I would really appreciate it.
To summarize the problem: I am trying to load a png (attached), created in gimp which has a transparent background. In any photo viewer the checkered pattern shows up indicating that the background is being saved transparently correctly. I have tried playing around with each possible RenderTarget blend mode when drawing and this does not seem to help, and regardless from what I have read sfml automatically uses the alpha channels in png files. Ideally I want the transparent part of the sprite to not block the images behind it, as it is there is a black rectangle around every sprite. The simplest demonstration I can make of this is as follows:
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow app(sf::VideoMode(960,540,32),"SFML alpha test");
sf::Event event;
sf::Texture texture;
sf::Sprite sprite1;
sf::Sprite sprite2;
texture.loadFromFile("alpha2.png");
sprite1.setTexture(texture);
sprite2.setTexture(texture);
sprite2.setPosition(50,50);
while(app.isOpen())
{
while (app.pollEvent(event))
{
if (event.type==sf::Event::Closed)
app.close();
}
app.clear(sf::Color(128,128,128,128)); //set background to grey
app.draw(sprite1);
app.draw(sprite2);
app.display();
}
return 0;
}
If it makes any difference, I am using g++ and Code::Blocks from the Ubuntu repositories, and sfml 2 was compiled from the snapshot named "LaurentGomila-SFML-18f1b62"; the most recent version of SFML at the time of posting.
[attachment deleted by admin]