• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

HTML5 drawing text with ttf font on html

Kios

Member
I'm using gms 1.4.9999, steam version.

I'm trying to draw text using a ttf font through includes. I add it via font_add, on obj create, and then draw it on the draw or draw_gui event, etc.

It works fine on windows and i see the text, on the html5 export however it doesn't, it just doesn't print anything to screen.

If it set the font to a normal asset font with arial, it draw a black font normally.

I've searched the forums, but can't seem to find anything about it anywhere.
 

FrostyCat

Member
How about searching the Manual? The entry on font_add() clearly states there's a catch on the HTML5 export:
The Manual entry on font_add() said:
For the HTML5 target module, this function can only be used to add Web Fonts, but will only work if WebGL is not enabled - if WebGL is enabled then you must use an included font file.
 

Kios

Member
How about searching the Manual? The entry on font_add() clearly states there's a catch on the HTML5 export:
I clearly did.

As the manual states: "if WebGL is enabled then you must use an included font file",
Where: "name The name of the font to be added (eg 'Arial'), or the file path if the font is an included *.ttf file." So in my case name is "myFont.ttf".

So I did that, but it doesn't really work. Tried everything nothing would happen.

I got it "working" of sorts, by installing the font that I wanted in the OS, then using it like any other font. GameMaker turns it into a bitmap font on export and it just works.
I didn't want to have to do that though, I'd hope i could just leverage the ttf, and load the font at runtime, as needed. That's what i'd do in a normal web game.

Thanks for taking the time to reply!
 

Kios

Member
I also tried adding the font-family via css, and calling it by name in the code to see if it would work. I mean, if it's a matter of availability and all. But it didn't.
Then i figured hey is this even working at all? So I also tried with 'Arial', and it also doesn't work, which makes sense given the other tries failed.
At least the css(adding the font manually) should have worked if the function was working.

So unless I'm missing something it seems font_add doesn't work with the html5 module, on version 1.4.9999 windows/steam at least.
 

chmod777

Member
I also tried adding the font-family via css, and calling it by name in the code to see if it would work.
I remember there was an issue with font_add() in HTML5 but this did work when doing like this (at least in previous releases).

Custom index.html :
Code:
<style>
@font-face {
   font-family: "myFont";
   src: url("mygame/myFont.ttf");
}
</style>

<p style="font:'myFont'"></p> (otherwise the browser won't load the font)
In GameMaker:
Code:
myFontIndex = font_add("myFont", 80, false, false, 32, 128);
draw_set_font(myFontIndex);
 

Kios

Member
I remember there was an issue with font_add() in HTML5 but this did work when doing like this (at least in previous releases). ...
Yeah, I actually had tried all of that :(
I hadn't done the last part:
<p style="font:'myFont'"></p>

But the correct way, I believe is:
<p style="font-family: myFont"></p>
Either way, I think font is supposed to be used in the browser if you set a size also, like "font: 1em 'myFont'".
Because it generally pertains to the formatting of a specific font in the tag. I tried with both though, tried everything.

Regardless, nothing worked.

Thanks for the heads up, it was worth the shot.
 
Top