Git Product home page Git Product logo

Comments (17)

Megaxela avatar Megaxela commented on August 18, 2024 1

I checked out https://github.com/akrinke/Font-Stash/. It's pretty interesting, but it's renderer uses OpenGL Compat Profile, that's not usable with OpenGL Core Profile. So font rendering algorithm will be reimplemented for OpenGL Core Profile. Also there is an stb as dependency, and GWork has it already.

ResourceLoader may be used with sth_add_font_from_memory.

from gwork.

billyquith avatar billyquith commented on August 18, 2024

May be because the STB pre-renderer characters don't include those outside ASCII range?

from gwork.

Megaxela avatar Megaxela commented on August 18, 2024

from gwork.

billyquith avatar billyquith commented on August 18, 2024

I think this is your problem because pre-rendered text

from gwork.

billyquith avatar billyquith commented on August 18, 2024

Yes, that may be true. But also typedef for UnicodeCharacter defined as
1 byte char may be a part of a problem.

All the text is UTF-8, but yes, I haven't dealt with multi-byte character encodings on all platforms. I don't know how STB font render works with UTF-8 multi-byte codes.

from gwork.

Megaxela avatar Megaxela commented on August 18, 2024

from gwork.

Megaxela avatar Megaxela commented on August 18, 2024

I researched problem and found several places.

  1. In PlatformType.h type UnicodeChar is char so useful data will be cut out.
  2. No conversion from UTF-8 to unicode values (in renderers). It can be fixed with utfcpp library.
  3. stb library can bake Unicode characters, but it can accept only first character unicode index and number of character to render. It has no any interface to perform more flexible baking. It may be a problem if required to render only specific sets of glyphs. Maybe project requires another (or modified) system of font baking. (I guess, just copy and modify stbs stbtt_BakeFontBitmap function can be enough. Also, this function is rendering all unknown symbols multiple times, instead of just once. (see img))
    image

from gwork.

billyquith avatar billyquith commented on August 18, 2024

In PlatformType.h type UnicodeChar is char so useful data will be cut out.

Ok, that can be made an int.

No conversion from UTF-8 to unicode values (in renderers). It can be fixed with utfcpp library.

I don't really want to have dependencies on many external libraries. Is there specific functionality that is required? I think UTF-8 to int may be all that is necessary and that is a one function that could go in Utility.

stb library can bake Unicode characters, ...

Yep. I think Allegro just bakes characters on the fly, whatever they are. I just added this range to get this to work. I mainly use Allegro so that is probably the most complete solution here.

Does STB remember the baked information? I.e. can you later bake more characters into the same texture? In which case you could just cache them like Allegro. And render from the cache.

from gwork.

Megaxela avatar Megaxela commented on August 18, 2024

Ok, that can be made an int.

I guess uint32_t would be better. But yes, 32 bit variable will be enough.

I don't really want to have dependencies on many external libraries.

It's pretty small, and contains of only several headers. But I'm agree, that dependencies are bad.

Is there specific functionality that is required?

I guess yes, because utf-8 is a specification, where one symbol can be described in range of 1 to 6 bytes, but after decoding it will describe maximum 4 byte variable. But I think I can implement it myself without any particular problems.

Does STB remember the baked information?

Nope, It's just saving 1 byte per pixel image to buffer. It's not caching glyphs. I guess I can cache buffer for font and if required - add symbols to it, then update texture in GPU and continue rendering. This implementation also requires custom baking function.

from gwork.

billyquith avatar billyquith commented on August 18, 2024

I guess uint32_t would be better.

Agreed.

But I think I can implement it myself without any particular problems.

If the cpplib license is liberal you could copy the function and attribute it? I think a lot of the other functionality should be handled by C++1x.

I guess I can cache buffer for font and if required...

TBH I don't know what is required here. Maybe have a look at the Allegro strategy. I think they have multiple texture glyph atlases. New one added when it fills up. Each new font/glyph/size is cached when it is used. Not sure how easy this would be in STB. Perhaps need a rect packer (which I think STB has).

from gwork.

billyquith avatar billyquith commented on August 18, 2024

Perhaps this is what is needed: https://github.com/memononen/fontstash

Font stash is light-weight online font texture atlas builder written in C. It uses stb_truetype to render fonts on demand to a texture atlas.

The code is split in two parts, the font atlas and glyph quad generator fontstash.h, and an example OpenGL backend (glstash.h).

  • 1 file dependency for fontstash and one per backend. 👍

This modification sounds interesting: https://github.com/akrinke/Font-Stash/ from memononen/fontstash#24.

The idea with the ResourceLoader is that there could be different flavours and users can choose an appropriate one. Likely, they would write their own because most games have their own resource management. Perhaps another one could be added that supports FontStash, and/or its variant (@akrinke).

from gwork.

billyquith avatar billyquith commented on August 18, 2024

I checked out https://github.com/akrinke/Font-Stash/. It's pretty interesting

I guess a concern is that it looks like a significant fork from fontstash, and that receives bug fixes and new features, so this fork would get less/no support. But I guess if it's all functional and looks reasonable to maintain then it will effectively just become part of GWork.

from gwork.

billyquith avatar billyquith commented on August 18, 2024

Might be useful https://github.com/DuffsDevice/tinyutf8

from gwork.

Megaxela avatar Megaxela commented on August 18, 2024

Hmm. This is extremely interesting library. First of all it has to be tested a little bit and if everything will be fine, it can replace standard string without any problems, I guess.
The only question to that library: why is this library using any .cpp files, if it would be better to implement it like "single header" library.

from gwork.

billyquith avatar billyquith commented on August 18, 2024

if it would be better to implement it like "single header" library.

Ah. I thought is was single header as no source directory (cpp in "Lib"!).

License is liberal. If necessary you could take what you need and attribute?

from gwork.

topblast avatar topblast commented on August 18, 2024

I was playing with https://github.com/memononen/fontstash on the DirectX11 renderer. This method is a better solution than the hack of expanding the limited character range.

static const wchar_t BeginCharacter = L' '; // First Character of Wide Character Table
static const wchar_t LastCharacter = 0x2FFF; // Last Character of Wide Character Table
static const wchar_t NewLineCharacter = L'\n'; // New Line Character

topblast@e2b3e6e
I am planning to update the DirectX11 renderer to use a similar implementation that fits better into GWork; it should be portable into OpenGL* and possibly other renderers.

from gwork.

billyquith avatar billyquith commented on August 18, 2024

I'm gong to turn this into a bug and open a new issue for the "font module" #88 new feature.

from gwork.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.