Antialiasing problem with buttons

Started by roHn, 10 October 2019, 16:36:35

roHn

Hello, I have an issue where my buttons look ugly and not smooth. I am using SFML RenderWindow with antialiasing level set to 8. Do I have to configure anything else to have smooth buttons?
I have circle shapes in my window and they are perfectly smooth.

Here are the screenshots where I used themes included within TGUI folder (BabyBlue.txt and Black.txt) :

texus

Can you try adding "Smooth" behind the texture in the theme file?
So the lines in the Button section in BabyBlue.txt should look like this:
Code (ini) Select
Texture = "BabyBlue.png" Part(269, 40, 90, 60) Middle(30, 0, 30, 60) Smooth;

I never really saw any difference between enabling smoothing on textures before so I just kept the default (which is false in sf::Texture).
Although I can't reproduce the way it looks for you, when zooming in on the button I can see a difference between non-smoothed and smoothed here, so this looks like it might solve your problem.

roHn

#2
Hi texus, thanks for your reply!
Adding smooth after texture in theme file did solve my issue.

One thing I noticed is that when I am creating these buttons manually, for example:

_theme.load("TGUI/themes/BabyBlue.txt");
tgui::Theme::setDefault(&_theme);

auto cmdBtn1 = tgui::Button::create("Button1");
cmdBtn1->setPosition({ "(&.width - width) / 2", 100});
cmdBtn1->connect("pressed", [this] () -> void {
_states->push(std::make_unique<GameState>(_window));
});
cmdBtn1->setSize(buttonWidth, buttonHeight);
_gui.add(cmdBtn1, "cmdButton1");

It doesn't have smooth texture(i.e. I have to manually edit theme files).

When I use the GUI-Builder and use the form.txt file to load widgets (i.e. _gui.loadWidgetsFromFile("..."); ) all textures are smooth.

Thanks again!

texus

The gui builder shouldn't have different behavior.
However, the widget files created by the gui builder embed the theme in them, so they don't read the theme file when loading them. Maybe you had a changed theme file at the moment you generated the widgets file with the gui builder or at the moment you opened the gui builder? You can check this by seeing if the form file contains the "Smooth" or not, it doesn't contain it by default (since the properties are copied from the theme files which don't have it).

roHn

#4
Actually, you are right!

I created smaller buttons inside GUI-builder and it looked smooth in my window. When I created larger buttons, I started to see the non-smooth texture again.
So, yes, GUI-Builder is nothing different than creating the buttons manually in terms of texture smoothness.

As a reference, the buttons size used in the screenshots I attached were 256x64 on a window 800x600