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

Author Topic: Full anti-smoothing of text / no aliasing in 2.6.x  (Read 2003 times)

0 Members and 1 Guest are viewing this topic.

NightShadeI

  • Newbie
  • *
  • Posts: 7
    • View Profile
Full anti-smoothing of text / no aliasing in 2.6.x
« on: March 18, 2023, 10:47:16 am »
Hi SFML team,

I'm trying to setup a simple example where text will not have any aliasing applied. I notice in 2.6.x we add the ability to setSmooth(false) on a given sf::Font

Unfortunately, this is making little to no difference to me, Will provide a minimal example below and a desired outcome. I have also tried some of the usual, earier tricks ive seen suggested online. Let me know if font file would help.



Top is desired (notice no aliasing), bottom is what the code produces. Note I have zoomed in here

Can use below code to reproduce in SFML 2.6.0 , I am using a windows 10 operating system

#include <SFML/Graphics.hpp>

int main() {
    sf::RenderWindow myWindow{sf::VideoMode{800, 600}, "Demo", sf::Style::Close};
    myWindow.setFramerateLimit(60);

    static constexpr uint32_t TEXT_SIZE = 14;

    const sf::Font myTimesNewRomanFont = [](){
        sf::Font myFont;
        myFont.setSmooth(false);
        myFont.loadFromFile("playground/fonts/times.ttf");
        const_cast<sf::Texture&>(myFont.getTexture(TEXT_SIZE)).setSmooth(false);
        return myFont;
    }();

    sf::Text myText{"English", myTimesNewRomanFont, TEXT_SIZE};

    while (myWindow.isOpen()) {
        myWindow.clear(sf::Color::White);

        myText.setFillColor(sf::Color::Black);
        myText.setPosition(sf::Vector2f{(int)200.f, (int)200.f});
        myWindow.draw(myText);

        myWindow.display();

        sf::Event myEvent;

        while (myWindow.pollEvent(myEvent)) {
            switch (myEvent.type) {
                case sf::Event::Closed:
                    myWindow.close();
                    break;
                default:
                    break;
            }
        }

    }
   
    return 0;
}
 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Full anti-smoothing of text / no aliasing in 2.6.x
« Reply #1 on: March 18, 2023, 02:28:39 pm »
You have to either use a font that is designed to not be aliased or not much, I often use fonts from this BitFontMaker2 site.

HelvetiPixel would for example then look like (scaled):



The only alternative is to modify SFML and load the glyphs with FT_RENDER_MODE_MONO.

New Times Roman with that change (scaled):



There's one trick, I've seen someone use, but it doesn't necessarily work for small font sizes like the 14 you're using or detailed/serif fonts, you use a larger font size and scale the text to the desired size, this way you get the aliasing of the large font size, but scaled down to the smaller size
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

NightShadeI

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Full anti-smoothing of text / no aliasing in 2.6.x
« Reply #2 on: March 18, 2023, 02:36:47 pm »
Thanks eXpl0it3r, very much appreciate the reply!

I guess for now I'll look into modifying the source or other fonts like you suggest. Do you think it would be possible to add the ability to load with FT_RENDER_MODE_MONO into 2.6.1 for example? I can see this has been requested on and off over the years , and maybe now might me a good opportunity to add some ability to in combination with setSmooth change? Would that be realistically easy to do

I would infinitely appreciate that if it's not too much work :)

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Full anti-smoothing of text / no aliasing in 2.6.x
« Reply #3 on: March 19, 2023, 04:19:01 am »
It should be clarified here, especially if it's being considered to be added to the UI of SFML, that aliasing is the effect of having jagged edges and defined, sharp pixels. Anti-aliasing is the removal of such sharp edges by using methods of smoothing those with semi-transparent (or just different shades) pixels around the edges.

I confess to being confused when first reading your original post as it seemed like you wanted the second (smoothed) image and had to read it in full, twice, to understand that you actually want the aliasing.

I only mention it in case there is confusing if/when implementing it into SFML (if that actually happens) :)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

NightShadeI

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Full anti-smoothing of text / no aliasing in 2.6.x
« Reply #4 on: March 19, 2023, 04:52:38 am »
Ah yes definitely worth mentioning, thanks for correcting. Sorry a lot of the terminology is still new to me so sometimes I do misuse it. Yeah to be clear it would be very useful to allow aliasing in 2.6.x , especially now we're providing the setSmooth method , it makes sense in my opinion.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Full anti-smoothing of text / no aliasing in 2.6.x
« Reply #5 on: March 20, 2023, 09:33:19 pm »
We won't be adding any features for SFML 2.x

I could potentially see something for SFML 3, but also remember we had this discussion in the past and Laurent had some reservation on using this, so would have to dig up some of the older discussions.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything