ppy / osu-framework

A game framework written with osu! in mind.
MIT License
1.61k stars 402 forks source link

Missing colour support in Font atlases #4374

Open EVAST9919 opened 3 years ago

EVAST9919 commented 3 years ago

Currently any colour in font atlas will become white. Atlas example: goldFont-uhd_0 Result: Аннотация 2021-04-17 153423

bdach commented 3 years ago

Maybe what is really needed here is a way to achieve the same visual effect (so e.g. vertical gradient & shadow on text) without resorting to using bitmaps raw. It might even be possible to set gradient colour on text already? Not sure.

EVAST9919 commented 3 years ago

Gradient is possible, yes. For this particular example the main problem is outline. Though it can be recreated using BufferedContainer, however there's a big performance hit once this container is being scaled (I mean transforms). Yes, you can use RedrawOnScale = false, but then visuals will suffer.

bdach commented 3 years ago

Ah right, I missed the outline due to dark theme. That does seem to be a bit of a problem...

Maybe this should exist alongside SpriteText as a RawSpriteText or similar and make that use source colour? Not sure.

EVAST9919 commented 3 years ago

Can you please tell what should I change (if it's a simple one) so at very least I can use local framework? I can't really find the point where the colour is specified.

peppy commented 3 years ago

You have two options:

https://github.com/ppy/osu-framework/blob/2b1dd17b9caae24d38a0075adad5db1b6c3759d3/osu.Framework/IO/Stores/RawCachingGlyphStore.cs#L77-L78

and

https://github.com/ppy/osu-framework/blob/2b1dd17b9caae24d38a0075adad5db1b6c3759d3/osu.Framework/IO/Stores/RawCachingGlyphStore.cs#L119-L126

            Fonts.AddStore(new TimedExpiryGlyphStore(Resources, "font"));

Note that the second will take a touch longer to load (and will have a temporarily higher memory footprint) as it is no longer benefitting from caching the PNG content to disk. You'd probably want to only use this for the fonts you need to. But you can also use it without a local framework fork.

smoogipoo commented 3 years ago

If you want to fix it, you have to know that RawCachingGlyphStore caches the glyph pages as alpha maps.

The createCachedPageInfo() method creates the alpha map, specifically through the following code: https://github.com/ppy/osu-framework/blob/eca80e83b118de60b745300791ce3b448ab7985c/osu.Framework/IO/Stores/RawCachingGlyphStore.cs#L71-L95

The createTextureUpload() method reads the alpha map, and creates the resulting per-character texture upload.

EVAST9919 commented 3 years ago

Thanks!