kaboom icon indicating copy to clipboard operation
kaboom copied to clipboard

Enable normal fonts?

Open amundo opened this issue 4 years ago • 4 comments

Would it be possible to enable non-bitmap fonts in text?

I know it’s possible for canvas, but I haven’t looked into your implementation:

https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Drawing_text

I have always wanted to try making a game where the "sprites" are emoji!

amundo avatar Aug 03 '21 20:08 amundo

Kaboom rendering is based on WebGL, using truetype / opentype fonts in WebGL requires bit of a hustle and probably need external dependencies to parse them. I also would really like to have them but unfortunately it's not the biggest priority at the moment, will definitely support in the future.

slmjkdbtl avatar Aug 03 '21 22:08 slmjkdbtl

Okay, retro is cool too ;)

amundo avatar Aug 03 '21 22:08 amundo

Thanks for understanding!

slmjkdbtl avatar Aug 03 '21 22:08 slmjkdbtl

(note to myself) Did a bit of research and this might be an easier implementation that can be done in near future:

  1. use FontFace API to load the font
  2. draw the font on a global offscreen <canvas> with 2d ctx
  3. use that offscreen 2d canvas as a WebGL texture and draw it
  4. clear offscreen canvas, redraw, and update texture (stored on each text() comp) on text change

slmjkdbtl avatar Aug 03 '21 22:08 slmjkdbtl

It's implemented on master and kaboom@next, see new examples/text.ts

slmjkdbtl avatar Oct 04 '22 16:10 slmjkdbtl