Antialiasing problem with buttons

  • 4 Replies
  • 41 Views
Antialiasing problem with buttons
« on: 10 October 2019, 16:36:35 »
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

  • *****
  • 1475
    • View Profile
    • Texus's Blog
Re: Antialiasing problem with buttons
« Reply #1 on: 10 October 2019, 18:01:40 »
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:
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.

Re: Antialiasing problem with buttons
« Reply #2 on: 10 October 2019, 18:16:16 »
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:
Code: [Select]
_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!
« Last Edit: 10 October 2019, 18:18:56 by roHn »

*

texus

  • *****
  • 1475
    • View Profile
    • Texus's Blog
Re: Antialiasing problem with buttons
« Reply #3 on: 10 October 2019, 18:56:19 »
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).

Re: Antialiasing problem with buttons
« Reply #4 on: 10 October 2019, 19:14:45 »
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
« Last Edit: 10 October 2019, 19:17:57 by roHn »