vydd / sketch

A Common Lisp framework for the creation of electronic art, visual design, game prototyping, game making, computer graphics, exploration of human-computer interaction, and more.
MIT License
1.4k stars 67 forks source link

The appropriate way to set a custom font #48

Closed VitoVan closed 7 months ago

VitoVan commented 2 years ago

Currently, I use the following code to achieve the custom font:

(set-font
 (make-font
  :face (make-instance 'sketch::typeface :filename "/tmp/my-stupid-font.ttf")))

I basically know nothing about SDL, and know very little about Common Lisp.

And the code above used something like sketch::typeface, which makes me feel inelegant. Since the double colons (::) tell me that you do not want me to use it.

So I am wondering:

Is this the proper way to set a custom font?

If not, what should I do?

Thank you very much for creating sketch, I enjoyed it very much.

dawranliou commented 2 years ago

Hi @VitoVan, I happened to be looking at the QELT repo and found sketch:load-resource the function you are looking for. This function checks the resource's file extension and creates the typeface instance so you can do:

(set-font
 (make-font
  :face (sketch:load-resource"/tmp/my-stupid-font.ttf")))