UnicodeFonts and Anti-Aliasing

I’m trying to implement unicode fonts with anti-aliasing. I have a lighting engine with shaders that relies on this blend function:

 glBlendFunc(GL_SRC_ALPHA, GL_ONE); 

I’ve even tried putting anti-aliasing through the displays pixel format:

Display.create(aaEnabled ?  new PixelFormat(8, 0, 0, 4) : new PixelFormat()); 

I’ve googled it and they all said to change it to something different, that didn’t work. I load my fonts through this method:


public UnicodeFont setupFont(String fontName, int size, Color color) throws SlickException, FontFormatException, IOException{
		
        InputStream inputStream = ResourceLoader.getResourceAsStream("project-assets/resources/fonts/" + fontName + "/value.ttf");
	Font awtFont = Font.createFont(Font.TRUETYPE_FONT, inputStream);
        UnicodeFont font = new UnicodeFont(awtFont, size, false, false);
        
        font.addAsciiGlyphs();
        font.addGlyphs(0x3040, 0x30FF);
        
        font.getEffects().add(new ColorEffect(color));
        
        font.loadGlyphs();
        
		return font;
	}

This is how it turned out:

I assume this is LibGDX…

The anti-aliasing you’re enabling is MSAA, multisample anti-aliasing. It only works on geometric edges, not on shader aliasing. I don’t know how LibGDX renders those fonts, but it probably doesn’t construct a mesh for each letter. Instead it renders the font to a texture and samples it, or it calculates the color of each pixel in a fragment shader. In either case, it’s still just a quad for each letter, so MSAA does nothing at all.

This is actually the full version of slick (not slick util) with LWJGL. It is the only thing I could find with UnicodeFonts.

So how do I implements a different type of anti-aliasing?

Texture filtering? Sorry, I don’t know much about Unicode fonts. All I can tell you is why MSAA probably isn’t working. :emo:

I fixed it, I know TrueTypeFont is deprecated, but it works for now.


	public TrueTypeFont setupFont(String fontName, int size, Color color) throws SlickException, FontFormatException, IOException{
		
		InputStream inputStream = ResourceLoader.getResourceAsStream("project-assets/resources/fonts/" + fontName + "/value.ttf");
		
		Font awtFont = Font.createFont(Font.TRUETYPE_FONT, inputStream);
		
		awtFont = awtFont.deriveFont(Font.PLAIN, fontSize);
		
		TrueTypeFont font = new TrueTypeFont(awtFont, true);
		
		return font;
	}