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

Author Topic: Texture Alpha Channel Transparency  (Read 4801 times)

0 Members and 1 Guest are viewing this topic.

xion911

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Texture Alpha Channel Transparency
« on: July 15, 2015, 07:45:39 am »
Does SFML support semi-transparent values in textures? For example, here is a gradient displayed with SFML: http://bit.ly/1Gl7FKJ
And this is what it should look like: http://bit.ly/1Gl7AGS

So it seems like the alpha channel is being rounded to either 0 or 255 at some point. This makes semi-transparent edges become jagged. example: http://bit.ly/1Gl81Rt
should be smooth like this: http://bit.ly/1Gl87sp

I have tried setSmooth but that seems to make no difference. I also tried loading the image as an sf::Image and using the alpha channel with createMaskFromColor.  Has anyone else experienced this, or found a solution?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Texture Alpha Channel Transparency
« Reply #1 on: July 15, 2015, 08:44:47 am »
No, alpha channels work just fine in textures, you must do something wrong.

Reproduce your issue with a minimal complete example.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

xion911

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Texture Alpha Channel Transparency
« Reply #2 on: July 15, 2015, 09:19:04 am »
Just set up this quick test and got the same result. I must be missing something. Here is the image I am using in case that helps. https://www.dropbox.com/s/u2sqtf73hpvx3k0/alphaTest.png?dl=0
#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
        sf::RenderWindow App(sf::VideoMode(1920, 1080), "Test");

        sf::Texture image;
        sf::Sprite logo;

        if (!image.loadFromFile("assets/images/alphaTest.png"))
        {
                std::cerr << "Error loading image" << std::endl;
                return (-1);
        }

        logo.setTexture(image);

        App.clear();

        while (App.isOpen())
        {
                sf::Event e;
                while (App.pollEvent(e))
                        if (e.type == sf::Event::Closed)
                                App.close();

                App.draw(logo);
                App.display();
        }
        return (-1);
}

EDIT: I'm an idiot. I moved App.clear(); inside the while loop and now it works.
« Last Edit: July 15, 2015, 09:23:23 am by xion911 »