satoshinm / NetCraft

Web-based fork of fogleman/Craft ⛺
https://satoshinm.github.io/NetCraft/
MIT License
56 stars 13 forks source link

Use browser text rendering instead of a fixed bitmap? #169

Open satoshinm opened 7 years ago

satoshinm commented 7 years ago

Craft includes its own font.png and sign.png, and only supports characters from these fonts, plain 7-bit ASCII. But there's many more possible characters, https://www.spigotmc.org/threads/websandboxmc.232807/page-4#post-2444596 asks:

only English? Can this plugin support other language such as Chinese? I can't see any correct Chinese word in chat or on sign through webpage

sign font

Investigate whether it is possible in the browser port to use the browser's built-in text rendering APIs, for full Unicode compatibility. Canvas API drawing text: https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Drawing_text

satoshinm commented 7 years ago

https://stackoverflow.com/questions/25319040/display-text-with-webgl recounts the same bitmap font rendering technique Craft already uses, but there is an (interesting) comment:

There also is my http://taccGL.org library that can draw HTML text on a 2D canvas and then use it as textures on 3D objects drawn on a 3D/WebGL canvas.

their website seems glitchy when scrolling but http://taccgl.org/tutorial/index.html describes an intriguing approach, "Combining HTML5+CSS with WebGL™ ". Could WebGL be used with CSS transforms to embed HTML objects within a WebGL scene? But back to text rendering, the approach of rendering to a 2D canvas then using it as a texture for 3D objects with WebGL seems feasible. Could even render more complicated textures to the canvas (video?).


The sign text is currently generated in src/main.c, _gen_sign_buffer and gen_sign_buffer

satoshinm commented 7 years ago

This may also allow for sharper text, when the window is resized the fixed-size bitmap font gets blurrier

twetzel59 commented 7 years ago

Would using Freetype solve the problem of internationalization?

satoshinm commented 7 years ago

@twetzel59 I think so (there's even an emscripten port of FreeType), as long as there is a suitably comprehensive font available, maybe https://www.google.com/get/noto/.